I have an xltx that clearly contains macros when i open it, based on the error "ThisWorkbook.RefreshAll err..etc .etc., due to invalid sql connection".
(whether i open the xltx as New or Open).
Once I go to vba project, there is ZERO code of any kind.
I consider myself a VBA expert, but have to confess, I've never worked at ALL with template files. (they seem like a completely unnecessary thing to me).
is there some magic that makes vba code invisible in xltx ?
You need to use XLTM (Excel Macro-Enabled Template)- the difference is the same as between XLSX and XLSM - you can write whatever code you like, but if you don't save it in the macro-enabled format, it won't still be there when you re-open the workbook/create a new spreadsheet based on the template.
You should have had this error message when you saved (although if you just clicked "Yes" it'll have saved anyway, just without the macro code)
If you haven't closed down the template file you're working on, you should still be able to save it as XLTM and retain the code - otherwise it's gone, unless it can be recovered from an autosave:
There will not be any macros in an .XLTX. You can try renaming the file as .XLSM or .XLTM in file explorer to get them back. The message "ThisWorkbook.RefreshAll err..etc .etc., due to invalid sql connection"." also looks like a broken link to a datasource rather than a macro.
Related
I wrote a macro that now is causing issues with MS Word. I can only open the document in safe mode and cannot figure out how to delete the macro from safe mode. I don't have access to any of the features in safe mode and the macro isn't even showing up. I tried changing the Trust Center settings but none of those options make a difference. Unfortunately I was very dumb and made it a macro on all documents so I can't open any documents without going into safe mode. help!
To be more specific, I believe the code that broke my MS Word was a OnError GoTo ErrorHandler where I tell it to skip to the next if there is an error. I am working on converting equations to a professional format and some of them don't have the right syntax for the conversion so for now I wanted it to ignore those equations and convert the next equation. That is the only change I have made recently that could be the problem.
An additional edit: the macro is coded to run on open. It was running fine before I added the ErrorHandler. I'm sure this is also a huge part of the problem, but a simple solution may not be the right fix since it automatically runs when I open the document. I can't access anything in safe mode.
If you are talking about the "Normal" document in the project explorer, resetting it is easy.
Simply navigate to %AppData%\Microsoft\Templates and either delete or rename the Normal.docm file. Once you reopen Word it will regenerate a brand new file automatically - one that contains no code.
You created an AutoOpen macro which only fires when a document is opened. Presumably this macro is stored in your Normal template.
When you first start Word the macro should not run as you are not opening a document. If Word doesn’t automatically create a new blank document you can safely do so. You will then be able to access and edit the macro you created.
I'm currently learning Excel VBA and since CTRL+Z doesn't undo anything, I'm trying to find a way to undo what my code does when I have to. On my office computer, I can click on the Save button from VBE and it saves my code, but nit the workbook.
On my personal computer (Office 365), when I do the exact same thing, it saves everything, code and workbook so I cannot undo what my code did by not saving it.
Can you help me to understand why? And do you have any idea I can undo what my code did?
Thank you
You have two options:
1) Export code modules to file - either manually by right-clicking on them, or via code (check out VBA Extensibility), or;
2) Do what I do, which is the easy option of just copying chunks of code as text into Notepad.
There doesn’t exist what you’re really looking for: an integral method of “saving” the VBProject but ignoring the workbook - as the VBProject is part of the workbook when it comes to file structure.
I have a macro which works fine on my computer when I click its button but it does not work on different computers.
All the macros on that excel file are not working when clicking on the button.
However, I have a macro working before saving. That means that when I try to save, another macro works properly. (that macro pop up an input message, but is not relevant now). So it seems that macros are not working only when you call them by a click...
The version of Excel is the same one and I enabled the macro when asked.
It is not a problem of the code because even if I create a new simple macro on that file from the different PC (such as:
msgbox("hello")
) it is still not responding.
I had a problem with that excel file in the past and I had to manually delete all the *.exd extensions in my computer. However once I deleted those extensions, the file worked well.
I believe that the excel file is considered corrupted by other computers and they do not enable the macro. This is just my impression but I cannot get why the macro is working when saving and not working when clicking.
Do you have any idea to solve the problem?
I had issues like that myself both with macros and with Excel workbook doing some really funny stuff (like formulas not calculating properly, or functions not working as expected etc) and I did not find any other solution then copying the content of the file and pasting into a newly created file.
In each case this resolved my problem.
It suggests that my files somehow got corrupted and the only solution was to save the contents and delete the files.
Exporting the .frm and .frx files from VBEditor (Modules and Forms) worked fine for me.
Have you tried this yourself?
This may be too simple a suggestion, but have you checked the security settings in Excel? The other computers may be set to a higher security setting that disables all macros without notifying the user.
https://support.office.com/en-US/Article/Enable-or-disable-macros-in-Office-documents-7b4fdd2e-174f-47e2-9611-9efe4f860b12?ui=en-US
I have an Excel 2010 file (.xlsm) that contains code in a few modules including ThisWorkbook. The ThisWorkbook module contains a few Event procedures, including a _SheetActivate event.
I have a button on one sheet that, when clicked, activates a different sheet.
Today after working on some code in one of the regular modules, I clicked the button and got a
Run time error '-2147417848 (80010108)'
Method 'Activate' of object '_Worksheet' failed.
Any attempt to activate a different sheet (manually or programmatically) crashes the Application.
After some extensive research, all I found was this page which gives further information regarding the error:
-2147417848 (80010108): The object invoked has disconnected from its clients.
Resolving the error isn't so much of a concern to me because I don't need that particular event anymore. However, I do need to figure out why Excel keeps crashing. I tried to delete the code, but Excel crashed. So I tried commenting the code out, but Excel still crashed. Alas, everything I've tried has resulted in a crash. This leads me to believe that something must be corrupt in the script within that module (the code in other modules seems to work fine, but none of the other procedures activate a sheet).
I've read that an option would be to copy everything (including code) over to a new workbook, but I'd like to avoid that if possible as that would require copying more than the current sheet...but I can't copy the other sheets without Excel crashing. Does anyone have any ideas on how I could remove/delete the code from ThisWorkbook?
After too many crashes to count, I was finally able to resolve the issue.
First I copied the code (Ctrl + C) from ThisWorkbook that I wanted to be able to use later and pasted it into a blank notebook file. Then I did as Patrick suggested and exported the regular modules.
At this point, I tried programmatically removing the code, but Excel crashed again. Then it dawned on me that I didn't have to delete the code manually or programmatically; I just saved the file as an .xlsx document which by design removes the code.
From there I closed the file, opened it back up, and imported the .bas files I'd exported earlier. The last step before I saved the file in .xlsm format was to paste the copied code from the first step back into ThisWorkbook.
Everything works like a charm now. Thanks for the help! Cheers!
I have an Excel 2007 Sheet with Macros. When I click on a button, it immediately pops up an error "File Not Found: VBA6.DLL"
Problem is, I have been using this sheet forever, and never seen this problem before. I did make some very very minor changes to the Macro code.
And, I have 2 other sheets with identical macro code which I made the same changes to. And those two sheets run fine.
Any ideas?
In this order:
Check your references (Alt+F11, Tools-References) to see if any are marked MISSING and make sure that Visual Basic for Applicatiions is checked.
Check the directory C:\WINDOWS\system32 for VBA6.dll
You may need to register VBA6.dll (Start->Run)
Regsvr32.EXE "C:\WINDOWS\system32\VBA6.dll"
I had the same problem with a shared file. The fix was as follows:
Un-share the file
Copy all macros; sheets, this workbook, modules and saved them in a text format.
Save the .xlsm as a .xlsx file
Save back to .xlxm file
Paste all macros back in
Reset shortcut keys and descriptions in macro options
Re-share the file
This worked without having to go to IT and get someone with administrative credentials to fix it.