Corrupt VBA Project Module Not Found Error - excel

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.

Related

Getting System Error &H80070057 (-2147024809)

I've been running a workbook with a few macros in it for a couple of years, and I've suddenly started getting this error thrown at me for some navigational buttons (shapes linked to macros that are simply ThisWorkbook.Sheets("sheet_name").Activate).
Other Macros within the workbook seem to work OK, but I can't get into the VBA editor to see any of the code anymore - I get to the VBA interface, but when I go to open the Module, nothing happens.
And to cap it all off, when I try to save the workbook, I'm just getting an error saying 'Document not saved'.
I had the same issue. I opened the VBA code module and then selected Debug then Compile VBAProject. I then closed the Visual Basic Editor and the error seems to have been resolved. Have only had the issue the once so can't be 100% sure it will work in every instance but worth a go.
Suggest you open a backup copy of this file (if you have one), export the broken module and then in your current file, remove the broken module and import the clean version.
We had the same problem in a file that was drawing data from an external source and saving itself automatically every minute. What worked for us was just replacing the entire file with a backup from 2 days ago.
We also had the "Document Not Saved" error, which was solved by upgrading the file from .xls to .xlsx
Just came across this error - for me it seems to affect any code opening docs via external links. Ran the debug suggested above and fixed issue.

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.

Opening Excel file from Sharepoint as Read-Write

I automatically open, edit, save and close several Excel workbooks from a Sharepoint location. The following code opens the workbooks (path loops through a list to hit each workbook name):
Workbooks.Open Filename:=path, ReadOnly:=False, Editable:=True
The files open in Read-Only mode, and the yellow dialogue option to Enable Editing does not appear.
I edit these workbooks manually and through a macro, but I am unable to save the files back onto the Sharepoint afterwards without saving as a new file.
I am using Excel 2013. This was working as intended about a year ago, but I believe there may have been updates to Office 365. I checked all of the Excel workbook security options, and nothing is set to open by default as Read-Only.
Is there any way to open the file in an editable mode through the macro, or at the very least allow the Enable Editing option to appear for each workbook?
I have been trying to fix the same problem for my files, and eventually did! So I felt that I could maybe let others know. And this old-ish thread came up near the top of my google search.
What fixed it for me was to edit the link.
from:
https://Company.sharepoint.com/:x:/r/teams/TeamNo/Shared%20Documents/Example/CoolFolder/TheBestExcelFile.xlsm
To:
https://Company.sharepoint.com/teams/TeamNo/Shared%20Documents/Example/CoolFolder/TheBestExcelFile.xlsm
Note that I only used replace to get rid of :x:/r/. I feel like I should have noticed this before but I didn't and no amount of meddling with the Workbook.Open parameters got me anywhere. It just seems odd that the default link copy thing gives you one with special commands in it. For our company most folders have spaces so the link has tons of "%20" in there so I simply read over the ":x:/r/".
Hope it helps someone.
Just for clarity, try this:
Sub Example()
'1.) Get filepath from somewhere
FilePath = Replace("https://Company.sharepoint.com/:x:/r/teams/TeamNo/Shared%20Documents/Example/CoolFolder/TheBestExcelFile.xlsm", ":x:/r/", "")
'2.) Open the file
Set StatisticsFile = Workbooks.Open(FileName:=FilePath, Password:="123")
'3.) Do things
'4.) Close the Sheet, save the changes. I simply like it this way, could be done in a single line.
StatisticsFile.Save
StatisticsFile.Close savechanges:=False
End Sub
I noticed this solution because I could still save the .xlsx file manually with the same name if I navigated to SaveAs. So if you guys can still do that after opening the file via macro, try a similar solution.
The interaction designed for Excel-OneDrive-SharePoint is new in 2016 apps and that version is a requisite to properly work.
The version 2013 may work by tweaking the OnDrive “Account” settings regarding Office co-authoring configuration which is specifically applied to Excel and Word
Right click the OneDrive icon in the taskbar to reach settings
Good luck!
I know your query was posted long ago but I have found the solution to remove the Read-Only blocker and update the excel document via Macro:
If you add "ActiveWorkbook.LockServerFile" after the code of opening the file, then it removes the Read-only and updates the excel as normal.

Personal Macro Workbook has gone missing (AGAIN)!

I don´t understand why, but it´s the second or third time I've lost my Personal Workbook with all my macro copies. The only different thing that I've done was editing a macro but, when excel was closing, I haven't saved the changes. Next time I've opened excel, surprise, surprise, no Personal Workbook! Has anyone had the same problem? Does anyone know why it happens? I have already searched in (I believe so) all possible folders where It could be stored.
Thanks!
the file can be found for 2007/2010 users in :
C:\Users\User ID\AppData\Roaming\Microsoft\Excel\XLSTART
or somewhere similar for others.
Hope this helps
The folder where the personal macros are saved can be found by using the command:
?Application.StartupPath (without "" sign) in VBA.
Open VBA (ALT+F11) and enter the command in the field on the bottom.
Hope this helped
Using Microsoft office 365. Lost Excel and Word Macros during last update. Had an Excel File that I had copied to my laptop (Windows 10) which had not been updated. Brought it up on my desktop. Was able to see modules but no content. Was unable to remove modules. Uninstalled Office 365. After reinstall, was able to see and use macros from that file. Word macro not retrieved. Hope it helps someone.
Mine went missing completely and was not in the xlstart folder. I finally discovered it was because I'm on a work server, files are all network storage based, and I had just changed my network password. I think the mis-match caused my links to personal files to be temporarily broken. I logged out completely, and back in, and everything was back where it should be.
In short: I tried turning it off and turning it back on again.
For those using MacOS / OSX (El Capitan) with Excel 2016 I located my copy of Personal Macro Workbook.xlsb, which I had previously unhidden in Excel, then closed, in the following location:
~/Library/Containers/com.microsoft.Excel/Data/Application Support/User/Personal Macro Workbook.xlsb
Please note that I used multiple search functions within OSX which did not return this file in the search results for some reason.

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