vba excel: Add-in in XLSTART ignored - excel

We have a vba excel Add-In installed in the users XLSTART folder. This works fine.
Now we did a small code change in a function and tested it on the developer machine. This works fine as well.
After deploying the Add-In, it's completely ignored by Excel. It's not loaded on start-up, no error message, nothing. If we copy again the old versin to the XLSTART folder, it works as expected. We did the same code change to a Word macro which is installed in the STARTUP folder. This one works fine.
Any ideas why the changed Excel Add-In gets ignored?

Possible reasons are:
It does not get opened
Permissions or macro security prevent it from functioning
THe original XLA is actually being loaded from somewhere else
I suggest you do some tests:
- When you look at Tools->Addins is the addin checked? If so it has been installed somewhere probably other than XLSTART
- when you place the revised addin in XLStart does it get opened and is it visible in the VBE?
- If you remove it from XLSTART and then open the XLA file as if it was a normal workbook does it work?

Just had this problem with a user. The reason was that the xla (ours is password protected) was not read-only. I know it is ridiculous but the xla was ignored until this changed.
Hopefully this will help others avoid such headaches.

Related

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.

Corrupt VBA Project Module Not Found Error

I have a workbook that was saved yesterday afternoon, and was working perfectly. I have opened it this morning, and none of the modules in the VBE are 'found'. Visually I can see them all sitting there.
When trying to open any of these modules to edit the code, the windows are greyed out, as below.
When I try exporting the code modules, I get the 'Module Not Found' errror.
Does anyone know a) why this has happened, and b) how can I fix this?
I thought initially it was the instance of my Excel, so have restarted the PC.
Any help is appreciated!
I managed to find a workaround to this problem, so sharing the solution in the event that someone else comes across a similar problem.
It seems that the VBA Project got corrupt somehow. Below, find some suggestions and workarounds in trying to solve something similar in the future.
This is what worked for me. Convert the .xlsm file to a .xls file. You can do this by changing the file extension when renaming the file.
You can also try to convert to .zip file type, and then convert back to .xlsm. Note: convert COPIES of your original, just in case.
Other suggestions (as Chris Nelisen suggested) are:
Export your VBA modules regularly
Save different versions as you are building
My workaround, works perfectly:
Open Excel in safe mode (pressing and holding Ctrl while you start
the program, or by using the /safe switch (excel.exe /safe) when you
start the program from the command line)
Open corrupted workbook (from safe mode, File->Open-> navigate)
Do not enable macro if asked
Make sure macro is present (Alt+F11) - not necessary
Save as new workbook
Close safe mode excel
Open saved workbook as usual
This is a well-described issue, and it exactly matches what I have just experienced (even including the fact that I haven't been versioning recently).
My file has an xlsb suffix. Resaving with a different suffix did not work for me on the same PC, but I emailed the file to another PC, opened it, saved as xlsm, sent it back to the original machine and it now works fine again. I can even re-save with my preferred xlsb suffix and it still works.
I've also run this script to make a backup of my modules:
Sub ExportVbaModules()
'Acknowledgements to Andy Pope [ozgrid thread 60787]
Dim objMyProj As VBProject 'if error, go to VBA editor - tools - References - Microsoft Visual Basic-Extensibility5.3
Dim objVBComp As VBComponent
Set objMyProj = Application.ActiveWorkbook.VBProject
For Each objVBComp In objMyProj.VBComponents
If objVBComp.Type = vbext_ct_StdModule And objVBComp.Name <> "" Then
objVBComp.Export "C:\Users\MyName\VbaBackups\" & objVBComp.Name & ".txt"
End If
Next
End Sub
The And objVBComp.Name <> "" stops it from erroring when it encounters a corrupted module but turned out not to be necessary as the 'fixed' file contained no corrupted modules.
Since that export routine is so fast (40 modules / 100kb saved in <1s) I will be assigning it to a button on the ribbon with a better naming convention for the files it creates.
I copied my .xslm file from my PC to my OneDrive account.
I open the file on my iPad OneDrive account and then export to Excel for iOS. The file opens and says links and macros are disabled. I then save a copy of the file back to the OneDrive account. I go back to my PC and open the file from OneDrive. I re-establish the links.
The macros are from a backup. This is an issue if you aren't backing up your macros.
Do you have this file on OneDrive?
If yes, I was facing that issue, and resolved restoring the last save. If you open OneDrive site (onedrive.live.com), find the file, and select Version History. Download the penultimate.
When this happens on 64 bit Excel, I simply open the exact same file in 32 bit Excel and the macros re-appear.
When this happens on 32 bit Excel, I simply open the exact file in 64 bit Excel and the macros re-appear.
Try to open the excel file in repair mode and save as the file one more time.
Open and Repair
I tried everything suggested and nothing worked. I could only see the module when I opened my VB editor. It was not available through the view macros ribbon shortcut. I was unable to export the module or copy it to a new workbook.
What finally worked for me was emailing it to myself, downloading it through my 365 outlook account via a web browser, and then the code was there.

Why does the VBA Excel Addin code disappears and doesn't function after I close Excel and open a new Excel file?

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.

PERSONAL.XLAM is being opened as read-only

I've been using a PERSONAL.XLAM file for years in Excel 2013(?) with no issue. I am now using Excel for Office 365 and am having a problem using the same file.
I used to be able to open a workbook, PERSONAL.XLAM would open along with it, and I could go into Developer > Visual Basic, and change VBA code and save. Perfect.
Now, with Office 365, I get an error saying I can't save because PERSONAL.XLAM is read-only. I checked the Windows file attributes, and the Read-only checkbox is not checked, so I'm not sure why it would be opening as read-only.
In addition to now using Office 365, I'm also on an entirely new PC, so there might be something I'm missing, but I don't know what to do.
Edit: I think I found a new wrinkle. I moved the Personal file from my XLSTART folder to my desktop. If I open the Personal file directly from there, I get an error that says, "Sorry, Excel can't open two workbooks with the same name at the same time." Does that mean it is open somewhere else already?
I figured it out. I actually had code in Workbook_Open that looked at the Application.UserName. If it wasn't a match for what it checked against, it made the Personal file read-only. And as I mentioned before, I got a new computer and my name was set to something different. After I changed my username back to what I used to use, everything is back to the way it was.
If it wasn't for that "security check," I wouldn't have had any issues. In other words, you can have the XLAM file in the XLSTART folder and make changes to it while you have it open, which is what I wanted.
This is obviously a self-imposed, yet accidental, issue. I'll mark it as answered, but if it would be better to close it, that's fine too.

EXCEL - Error while opening excel workbook

I have Office 2007.
Each time I launch Excel, or open an existing file, it tries to access some old file and I get the following error pop up:
'E:\xyz.txt' could not be found. Check the spelling of the file name, and verify that the file location is correct.
If you are trying to open the file from your list of most recently used files, make sure that the file has not been renamed, moved, or deleted.
Please help on this.
Thanks in advance!
Maybe you have an old add-in still active?
Developer > Add-Ins
if you see any custom add-ins, deactivate them and see if the problem remains.
Alternatively you could check in the VBA window what xla / xlam files are active and see if the file you mention is hiding somewhere in the code thereof

Resources