I have a VBA code that is opening a lot of different excel files with macros. However, every time VBA opens a file, it says "Microsoft Office has identified a potential security concern", and I have to select "Enable Macros". Is there a way to add a line, that would always choose "Enable Macros", as I cannot change any excel settings (it is a corporate computer, without admin rights)?
Thank you!
Typically when opening a macro-enabled file using code, there's no security prompt. It would help to show the code you're using to open the files.
However if you do see a prompt you can fix that by setting Application.AutomationSecurity to the appropriate value
See: https://learn.microsoft.com/en-us/office/vba/api/excel.application.automationsecurity
Related
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.
I created a simple vba addin that colors cells based on their value, and I created a function that calls it with a shortcut then I saved it as an Excel addin and added it to Excel.
The problem is the addin works fine when I add it the first time, but when I open a new Excel file, I need to disable and enable the addin for it to work.
Update: I tried it on another computer and it works, but it shows an error that when I ignore it works fine. I am adding screenshots for the error and code
Error Message
Code
Sometimes, Excel will open workbooks in another Excel Application. This second application can sometimes face some issues with addins. You should double-check that the new file is opened in the same Excel Application. By looking at the task manager:
In this example, I'm using Window 10 and you can see that Book3.xlsx is in a different Excel Application than Book2.xlsx and Book1.xlsx
EDIT:
This question could also be of interest to you. The accepted answer reads:
This problem results from security patch in KB31152, released in July 2016. According to private communication with Microsoft software engineers:
"With this update, we changed the behavior of Excel so that it will
not load certain file types (including .xlam) when they are untrusted.
The easiest workaround is to find the add-in that is causing you
trouble, right-clicking on it in Windows Explorer, and checking
Unblock"
An easier approach is to simply place the add-in in a Trusted Location
(in Excel, go to File > Options > Trust Center > Trust Center Settings
Trusted Locations), such as the following folder, and load it from there:
C:\Users\%USER NAME%\AppData\Roaming\Microsoft\Excel\XLSTART
EDIT2:
And don't forget the option of just restarting your computer just to make sure that the problem is still there.
My workplace has Excel's Trust Center settings for Macros locked to "Disable all macros with notification." This is usually fine as most of the macros we use are stored in the workbooks themselves, so all the user has to do is enable the macros once the document is opened.
However, we recently were given a useful add-in (.xla) that we're expected to start implementing.
However, the "Enable Macros" prompt only appears if the .xla file is opened manually. If the file is added to Excel as an actual Add-In (either through Excel's options, or by copying the file to the user's ...\AppData\Roaming\Microsoft\AddIns folder), the prompt does not appear.
Instead, if the user attempts to run the macro through the included keyboard shortcut, a prompt appears simply telling us that macros have been disabled for this workbook, and that it needs to be reopened.
Unfortunately the trust center settings are non-negotiable; these settings are managed site-wide and my issue is specific to my particular office.
I've attempted to run the add-in macros manually through the developer tab, but get the same result. I've also tried saving the add-in as the newer .xlam versus .xla, but again got the same result.
Is there any way to convince or trick excel into prompting the user to enable macros when using an add-in? Or are the users stuck with needing to open the file manually each day?
I am looking for a possibility to add an additional level of security to my Excel projects.
We have multiple users. Some who know (and are meant to) the password that unlocks the VBA macros. Others are not meant to be able to access these.
I'm not sure if someone has the password that shouldn't (changing the password hasn't stopped tampering) so i would like to disable the VBA editing window for any user not approved. I can't find any way to do this though, is it possible?
I can't disable the save option as all users need to save data.
I have tried to disable the ribbon icons etc, but with no sucess. It is still possible to open the code window with Alt+F11.
Any help would be great.
I am coming from Excel 2003, but this concept should work for you as well. You could think of
trapping the Alt-F11 key (Application.OnKey "%{F11}" "MyNullSub") plus
disable the relevant menu entries (Application.CommandBars(...).FindControl(ID:=..).OnAction = "MyNullSub")
with
Sub MyNullSub()
' do nothing
End Sub
as a dependency of an entry in the registry that needs to be present (GetSetting(...)), but this will only help until this additional secret is spread around in the same way the (changed) passwords apparently did.
I have some files that are saved a main file. When I try to open some brings a pop up about enabling macros but the file never displays. Any ideas?
the first thing you need to do is enable macros. this is a bit different depending on if you are using 2003/2007. you need to go to trust center and adjust your settings.
also depending on whether you are using 2003/2007 you need to get into your VBE visual basic editor and you will see all of your code there