Cannot unprotect Excel worksheet in VBA (Run-time error 32809) - vba

The code has worked on this machine previously. I worked from home yesterday on a machine which hasn't had the December 2014 Office updates removed.
I get the same error when running a little for loop which you can see commented out. Any suggestions? The sheet exists. Unhidden. Not password-protected.
Thank you!

It's happening early in the code, the worksheet might be corrupted. Copy and Paste that sheet to a new sheet and try again.
I know it's not a very in depth solution but I would try this before going crazy with different strategies.

Thank you all for the suggestions. I was able to solve this problem by following a bit of guidance from elsewhere, however.
I put a Worksheet.Select line in at the start of each Sub - just a simple line of code with no impact. Voila. Working since.
I'll stick to making mods on the one machine I use most frequently... for now.

Related

ExecuteMso error

This question may have been asked before.
I have tried using ExecuteMso in VBA but returns Method or data member not found.
Not sure what I am doing wrong or if there is an issue using this code as using excel on a Mac. I have also tried this on a windows version of Excel however it is a very old version (if that makes a difference?)
Any help or tips regarding this would be great.
Thanks in advance
The following sample executes the Copy button.
Application.CommandBars.ExecuteMso(“Copy”)
Otherwise, post what you have tried and what is giving you the problem.

Excel Personal Worksheet VBA Module's won't allow me to view code

My personal workbook (PERSONAL.xlsm) has stopped allowing me to view the code or any details of the modules I have saved there. It also will not allow me to run any of the Macros it once included. I don't know if they got deleted or are hiding somewhere (but I am hoping it is the later). I have not done anything out of the ordinary. Before this issue was happening all I had done with excel today was run one of these macros (without issue), make an edit to include the solver in a macro, and save it.
In addition to this problem there are a few others that seem to accompany it:
Occasionally when I close excel without saving a file, excel crashes.
If I attempt to record a macro (either in the Personal Workbook or to
another location) one of the following happens:
a. Excel crashes.
b. Excel gives me an Invalid Name Error (despite the name being perfectly valid.
It is worth noting that macros not saved in the Personal Workbook work just fine. I am very stumped and cannot find a solution to this problem anywhere. I have tried the obvious (rebooting my computer), the not so obvious (restoring previous versions of files), and the weird (disabling and enabling random things in the excel options section). Please, if you have a solution let me know!
Thank you in advance, all and any suggestions are appreciated!
I had a similar problem a while ago. I had to:
close Excel
re-name PERSONAL.xlsm to something else (like temp.xlsm)
open Excel and verify it does not "see" or attempt to open PERSONAL
create a new PERSONAL.xlsm
copy all VBA from temp.xlsm to the new PERSONAL.xlsm
Can't comment yet, so i apologize in advance.
It is definitely Excel at fault, it happens to me so often (on big files including VBA) that my before_save saves a copy of the file with time in its name, and all module's, userform's, sheet's code as *.frm, *.cls, *.bas.
I usually can also open corrupt files by holding SHIFT key (force designer mode) and then copy manually stuff.

Excel VBA App stops spontaneously with message “Code execution has been halted”

I have exactly the problem described here:
From what I can see on the web, this is a fairly common complaint, but answers seem to be rarer. The problem is this:
We have a number of Excel VBA apps which work perfectly on a number of users' machines. However on one machine they stop on certain lines of code. It is always the same lines, but those lines seem to have nothing in common with one another.
If you press F5 (run) after the halt, the app continues, so it's almost like a break point has been added. We've tried selecting 'remove all breaks' from the menu and even adding a break and removing it again.
We've had this issue with single apps before and we've 'bodged' it by cutting code out of modules, compiling and then pasting it back in etc.
The problem now seems to relate to Excel itself rather than a single .xls, so we're a little unsure how to manage this.
I have managed to resolve it with the accepted answer, but now, when I send the VBA file to my colleagues, they have the same problem.
My question and my problem is - any ideas what to do, as far as it is really not a good idea to go to everyone and to debug every time. And I somehow do not want to add Application.EnableCancelKey = xlDisabled to my macros.
Sounds like a ghost break. File saved one time with a break in there. What has worked for me in the past was to remove any breaks you see and manually step through the code (F8) through completion and then save file. Prob now necessay to step all the way through but I like to know I went all the way and didn't miss any.

Executing a macro in Excel sheet

I would like to execute a macro (VBA Code for formatting the sheet) in an excel sheet that i create from code. The approach I use right now is put the macro in the workbook_open
event and open the Excel sheet from code. That applies the formatting and I save it later. But this slows down the process a lot.
I would like to know if there is way I can execute a macro using the DocumentFormat.OpenXml SDK or some other .net class without actually opening the excel file thus improving performance.
I have gone through a lot of internet material , but all in vain. Maybe I am just too much into it that I am just overlooking a very simple solution.
Kindly advise.
Thanks
I would like to just point out for reference. The comment from Tim is the answer to this, for anyone looking for an answer. I cannot mark a comment as answer so just re writing it. Will mark it as answer until I find some better way to do it.
You'll have to open the file if you want to format it... – Tim Williams

Excel VBA File not Found

During the development of some Excel vba code, in about every other iteration where I go in, add some code and then save the file, the next time I open it, I get a "File not Found" error. The macro is set to automatically run the code upon opening the file.
To fix it, I copied all the code - modules and classes plus the startup code - to a fresh blank excel file. I save the excel macro file and it runs fine.
This happens for both Excel 2003 and 2007. What is happening here?
My psycho powers tell me you are relying on relative paths while changing the current directory.
I'm seeing a similar phenomenon, though I'm not sure the cause is the same.
Yesterday, every time I added a Workbook_Open procedure to my workbook, saved it and reopened it, I got the "File not found" error (no particular file specified). followed by "We found a problem with some content in [workbook name]. Do you want us to try to recover as much as we can?". If I said Yes to recovering, I found that all the VBA code was gone from the workbook.
It turned out that this was caused by my virus checker (BitDefender), which considered my code to be malware and was removing code from the workbook. I tried it on a PC with a different virus checker (BullGuard) and it did something similar. At least BullGuard had the decency to tell me it was modifying my file. BitDefender didn't give me any clue at all!
On a general point, as someone who does VBA work for many different clients, I'm finding more and more problems with virus checkers getting in my way.
Not sure if you have solved your problem.
One possibility is that one of your module is too long.
VBA is a compiled size limit for 64kb. It is "supposed" to warn you if you exceed that, but often it fails.
Find out the longest Module that you have, move some function out to another module and see if it helps.
I have this often.