What causes this popup in Excel VBA? - excel

I am making a simple tool for my job. It involves opening a file dialog box, selecting a file, opening it, analyzing it for different items, then creating a new workbook with the results. This is all done with VBA macros, activated via a command button.
The code works fine, all does what it's supposed to. However, at the start when the file dialog box is first opened, sometimes this error message pops up:
It doesn't affect the code or how it runs whatsoever, but it is a bit of a nuisance. There is no further detail provided for this "error". Does anyone know what might cause this popup?

Related

Excel code shows modules but with hidden code

i just recieved an e-mail with a virus embeded in xlsm format. So how i'm curious i wanted to check the code. Enabled everything of security on Excel to avoid events starting and other stuffs after opening the contamined file.
Kaspersky flagged the file instantly so i had to disable it.
So i opened the file, and excel showed me a prompt that i had to need disable some security features for the macro run normally. Well, i just ignored it and i went to the vba area to check the code and i found some modules, but every was empty.
Someone can explain me how is it possibile and if there's a way for me check the code?
Thank you.

VBA Workbooks stop working with upgrade to Excel 365 - VBA Compiling Issue?

Since upgrading to Excel 365, my company has been having all sorts of trouble with VBA-supported Excel workbooks crashing or not functioning properly. The issues have popped up in various workbooks and various departments, including seemingly simple VBA workbooks. I've discovered a fix (see below) but it's not sustainable.
The Issues
The various issues we have experienced are listed below. Note, these issues only occur when you open a file in Excel 365 desktop. The same files, when opened in the Excel 365 browser app or in Excel 2016 will work fine. Also, all these issues happen at random. A user may have been working in a file for weeks and then the next time they open the file they get one of these errors.
"Can't find project or library" errors even when we are using the standard set of libraries and basic VBA. Then when you open the VBA Editor window, all the VBA screens are essentially frozen up and the library list is inaccessible.
Excel hard crashes or locks up when opening these files and enabling VBA. Note, the crash only occurs when the VBA is enabled. If you open a file without enabling VBA, it will work fine (though obviously you can't use any of the code).
The file opens seemingly fine, but the VBA doesn't work and once again, everything is locked up when you access the VBA editor window.
"unhandled win32 exception occurred" error
when executing a command, getting an error 32809 which seems to indicate the compiled VBA has been corrupted
The Fix
Opening the VBA Editor window, then selecting Debug -> Compile VBAProject seemingly fixes the issue. I've yet to experience any of the above issues where the file had been manually compiled this way. The problem with this is that every time you add code to a file or any time you add a new tab to a file, you have to go in and perform this manual compile again.
Yes, apparently adding a single tab in a file changes the workbook structure enough that it is necessary to compile again. The Compiled VBAProject selection will be greyed out. But adding a tab (or adding new VBA) will un-grey it and require another manual compile or the problems start occurring again.
This fix also works to repair files where the above issues are occurring. To fix those files, you can:
Make sure "Disable Trusted Documents" and "Disable VBA macros with notification" are toggled on in your security settings so that VBA doesn't automatically run when you open a file.
Open the file with the errors but do not enable the VBA.
Go to the VBA Editor window, select Debug -> Compile VBAProject.
Save the file, close it, reopen it, enable the VBA, and everything works fine again.
But again, this isn't sustainable because all my users will have to remember to go compile VBA any time they add a new tab to a workbook.
Help?
Has anyone found a more sustainable fix to this issue? Is there a bug with the Excel 365 Desktop automatic compiler that Microsoft is working on?
I think I perhaps found an answer in this thread:
https://social.msdn.microsoft.com/Forums/en-US/814ac2ce-ab45-45dc-8c6a-8ef0775d189a/excel-64bit-crashes-when-activating-macros-but-excel-32bit-does-not?forum=exceldev&prof=required
Per that thread – “the cause is that Excel does not correctly save the compile state of the VBA code and 64 bit Excel cannot recover from that issue when opening the afflicted Excel file (32 bit usually can). A fix was released for only Excel 2016 and not for other versions". That would indeed confirm that it is a bug within Excel and explains why we only see the issue with 365 64 bit Excel.
That also explains why my manual compile fix works. Based on the article I found, there is a more sustainable fix. You can change Excel’s registry and force VBA to compile accurately.
To implement the permanent fix:
Open the start menu and type “reg” and select the “Registry Editor”
Navigate to: Computer\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\16.0\Excel\options
On the Edit menu, point to New, and then click DWORD Value.
Type ForceVBALoadFromSource, and then press Enter.
In the Details pane, right-click ForceVBALoadFromSource, and then click Modify.
In the Value data box, type 1, and then click OK.

What happens when you close a workbook with code running?

I have a workbook on a network containing worksheet data and housing a generous amount of data, VBA code, forms etc. I developed a custom ribbon available via an add-in that opens this file and executes a macro when a button on the ribbon is clicked.
When the ribbon button is clicked, it executes a callback within the add-in that houses the custom ribbon XML file.
Code within the callback uses Application.Run() to open and execute the much larger network file that holds the worksheet data and macros needed for a lengthy automated process.
If a user cancels operation via the "Cancel" button on one of several forms (or if code successfully completes execution), via Application.Run it passes code execution back to another procedure in the add-in housing the custom ribbon.
This "EndProcedures()" macro in the add-in closes the network file.
The issue I am having is that code execution stops (as if an "End" command had been encountered) as soon as I close the network file which houses the vast majority of the VBA code. Since the user has the ability to cancel operation in the middle of the macro, the procedure call to the "EndProcedures()" macro in the ribbon workbook (the one that code execution began from) is something like #8 in the call stack, with #2-7 being procedures residing in the workbook that is being closed by #8. Since I want to halt code execution and the next line in the "EndProcedures()" macro is simply the global "End" command anyway, this isn't necessarily an issue. However, for the last couple of days I have been wrestling with some cryptic errors that I am thinking may be tied to the fact that I am closing a workbook while it has code running in the call stack. I have been getting "Out of Memory" errors in the VBA editor (though strangely I haven't seen them when the VBA editor is not open), and my thought is that this is due to either:
The code window for the network file simply being open in the VBA editor after the file itself is closed by other VBA code, OR
Perhaps actual memory issues due to object references not being cleared because the file was unloaded, rather than an "End Sub" or "End" line being encountered.
Though I use custom objects extensively in the macros housed in the network file, I am very careful about memory usage with them (which shouldn't even be that much) and don't think that this code is the source of the "Out of memory" errors. The question for now is whether or not closing a workbook with VBA code while code is running in the workbook being closed can cause "Out of memory" errors, and if so what can be done so that once macro execution ends users don't have my macro workbook open to wreak havoc with. Will I really have to code proper "Exit Sub" lines all the way out of the call stack?
This is my first post to StackOverflow, even though I probably learned 50% of what I can do in VBA from here, so please bear with me on this one.
After a few weeks of continuing to play with this, it doesn't appear that exiting code execution in the middle of a call stack involving multiple workbooks/modules was the source of the "Out of Memory" issues that were encountered. Though I haven't been able to pinpoint which edits actually addressed the "Out of Memory" errors, at least the issue has been resolved to my satisfaction.
P.S. - I answered my own question because it was no longer an issue, not because I necessarily pinpointed a resolution. As this was my first post to StackOverflow, if this was not the proper action to take please let me know.

Excel 2007-VBA, Right Click Buttons

I am having a strange Excel 2007 issue, and I am not quite sure how to explain this. So bear with me please....
I have created a few right click buttons to call various backend VBA functions that I have written. They were working fine earlier today, and now for some reason, a button is appearing that is not from the code in my worksheet. When you click it, it is attempting to open another worksheet and execute code from it. The two files are not in the same directory nor are they named anything similar. I deleted the file that the button is trying to execute from and now it just simply gives me an error 400.
So, I couldn’t figure that out, and have since deleted every single scrap of code in the backend of this file, and the button still appears. Any ideas what could be causing this? It seems like maybe its mixing files up or saving a copy somewhere in a temp directory and trying to access that instead of the actual code that is written in the VBA. Is there a cache I need to clear out or something?
I know I didn’t exactly do a great job describing this, so I will be more than happy to provide any and all other details that you may need. Just let me know what is going on.
EDIT #1 -- New Information ==
I can even open a new, completely blank excel file and the right click button is still there.
EDIT #2 -- Tried Diagnostics ==
I just tried running the Excel diagnostics and it found no problems. It is strange, it is like this macro has somehow became global or stored in some type of cache or something.
I hope I'm understanding your issue correctly.
If you know what right-click (context) menus the button is appearing in you should be able to fix them with a Reset command. For example if it's appearing in the Cell context menu, you could try this in the VBE's Immediate window:
Application.Commandbars("Cell").Reset
This will reset the entire menu to its default state.
Also, you might be interested in a tool I wrote, MenuRighter, that allows you to tweak your right-click menus. It also has a setting to show you the Caption and ID of any context menu.

Excel 2007 automatically starts debugger when showing dialog

I have a UserForm and when I display it dlg.Show vbModal excel is entering the debugger. There's no error, it just enters the debugger - like it thinks it has hung. How do I stop it from enter the debugger?
Moving my comment to an answer so that this question doesn't get DELETED automatically.
Reason Why this happens:
For some reason, the VBA project thinks a breakpoint existed within that event script, so the VBA editor stops on that particular line of code, although there is no visible breakpoint seen.
Two ways to solve this problem:
As per THIS MSDN ARTICLE, select the Clear All Breakpoints option under the Debug menu.
If the above doesn't work, then simply re-start your pc. Remember to save your work if applicable.

Resources