Excel Workbook Crashing on Save and Visual Basic editor open - vba

A specific xlsm workbook crashes when I try to save, save as, or when I open the VBA editor. I've tried disabling macros, removing auto calculations, etc. I can't actually get to the code to see if there's a bug causing the crash due to the editor itself causing crashes.
Edit: Also forgot to mention there are links to another workbook in the file - but removing auto-updating/calculating upon save doesn't seem to help. Also, I'm able to modify the workbook, I just can't execute the macros, save, or open the VBA editor.
Edit2: Some additional info. I tried deleting all worksheets and still have the same problems so there must be something wrong in the code.
Looking for a solution to salvage the workbook.

Remove the VBAProject.bin file from the .xlsm file:
copy the .xlsm file
change the extension of the copy to .zip (say Yes to the warning about changing extensions)
open the ZIP file
open the xl folder
cut the VBAProject.bin file and paste it to somewhere outside the ZIP file
rename the ZIP file back to a .xlsm extension
You should now be able to open the .xlsm file in Excel but it will no longer have any macros.
It is theoretically possible to reconstruct the macros from the VBAProject.bin file using the resources linked to in this answer but this may involve considerable effort

Related

Vba do not open wbook

There isn't enough memory to complete this action" in Excel
How to fix it without opening file
İ want to turn calculation manual but without open it is impossible
In order to change the automatic calculation to manual without opening the .xlsx file, you can do this. Before doing this, be sure to make a copy of the file and try these manipulations on the copy.
Unzip the .xlsx as a .zip archive, open the file ...\xl\workbook.xml in a text editor, find a tag similar to the following <calcPr calcId="191029"/> and add to it calcMode="manual" so you get <calcPr calcId="191029" calcMode="manual"/>. Then save this file, package the entire directory, and change the extension to .xlsx.

Excel 2010. Automatically run macro from file with xlsx extension

I work with system, which automatically reads excel file, insets some date and sends to e-mail.
It works only with xlsx extension.
I need, that sending file have some format (borders and filling), so I would like to use macro.
How can I do, that macros automatically run from file with xlsx extension? Can I store macro in Person.xlsm file and run it when it is necessary?
Yes, macros cannot be saved in a .xlsx file. You can however use Workbooks.Open("filepath.xlsx") to open and edit another workbook from a .xlsm workbook. That is the way you should approach it.

A copy of Excel Addin is created in My Documents after saving

I have an application (running in IBM Notes, using Lotusscript etc.) that create a new Excel object via OLE automation. In my app I create a new Workbook and saving it to a temporary folder (I am saving it as Excel Worksheet w/o macros -> type 52) so that the resuting file is sth. like that:
tmp_abc1234.xlsx
Then I open the file in Excel programmatically. I have an Excel Addin (filename is "Teamoffice.xlam" loaded where some macros reside I will trigger in the custom save actionbar button. In this save method I also call the save function:
Call ActiveWorkbook.Save
Call ThisWorkbook.Save
For some reason Excel creates a file named "Teamoffice.xlsm" in the "My Documents" folder. The file itself cannot be opened in Excel ("wrong file format error") - of course, it's an Addin!
This works well if I have only one Excel document open from my application. If I open a second (or more) I run into trouble: everytime I save on of those secondary opened (or newly created) documents Excel asks me if I want to overwrite that "Teamoffice.xlsm" file.
I added VBA code to ma macro that detects if this file is there and tries to delete it. With no luck of course, as the first instance of Excel is locking that file already. Overwriting the file when aswering the Excel-question dialog works though, but I don't want that question to appear.
Excel doesn't behave like that when using it stand-alone w/o OLE.
Several questions resulting from this behavior:
Why does Excel create this file? Can I stop it from doing so?
How can I delete the file even if Excel has a handle on it or
Can I tell Excel not tohave a handle on this file (if it's there) and let me kill it?
Can I suppress the question dialog and always say "yes, overwrite it"?
Office version is 2010 - and it makes me going nuts... so thanks in advance!
p.s.: I am not that VBA pro, so please be as detailed as you can effort :-)
I noticed that
ThisWorkbook.Save
was the reason. If I omit it no file is created. Strange that this saved the Addin file as xlsm file though.

Why are EXCEL XLSM format no longer a valid ZIP format?

Files saved in Excel as XLSM files are no longer valid ZIP files, preventing editing of the Ribbon.
XLSM files saved on or prior to May 23, 2014, can be renamed .ZIP and edited.
XLSM files saved after May 23, 2014, cannot be renamed .ZIP and edited, but rather generate the error message that the file is a corrupted archive. Both Windows Explorer and WinZip generate the same error condition, though the error message varies slightly.
Yes, there are macros in the files; but even opening an old file with Macros (and VBA) disabled and immediately Saving As a new name generates a corrupted file.
I have also tested on 2 other machines in our corporate group, with the same results, so it is not a corruption just on my workstation.
Office Diagnostics reports no problems with EXCEL.
Any thoughts on causes or solutions?
Update
Let's be clear on my test process:
I rename an XLSM file saved on May 23 to .ZIP; this creates a zipped archive which both WinZip and Windows Explorer can open successfully. I then undo the rename to make the file an XLSM again.
I open the file above in EXCEL-2007 and do not enable macros or VBA. I save this with a new filename as an XLSM file.
I rename the file saved in step (2) as a .ZIP file. This file no longer opens in either WinZip or Windows Explorer, but generates the error message above.
I repeat steps 1 through 3 above on the workstations of two other colleagues - same result exactly.
Update #2
The problem seems to be file-related in some way, as saving an empty workbook as an XLSM still works. I will investigate more.
The problem is that one or more of the sheets are password protected. Unprotect the sheets, then save as xlsm, rename to .zip and voila, XML structure now appears.
Update:
Actually, it was an inconsistent setting of password-protection for the workbook rather than any worksheet.

How to Create VBA Add-In with Shared Codes for All Excels?

I'm writing VBA codes for multiple Excel spreadsheets, which will be shared with others from time to time. At some point I find there are lots of duplications in my works. So I want to find a way to share codes in a sort of Excel add-in, like the .xla file.
But when I tried to save the Excel file containing shared codes as .xla file, I got some problems:
The file cannot be edit anymore after I save it in the default add-in folder
If I move the .xls file to a folder other than the add-in folder, and open it directly - I cannot use its classes - which creates problems for sharing the codes
Any ideas to create add-ins in a flexible and powerful way please?
Thanks a lot for the help
Not completely sure this is what you're looking for, but ...
(1) save the .xla/.xlam code by clicking the save icon in the VBA editor. HOWEVER, the thing that saves is the thing currently selected in the Project Explorer pane, which lists all open VB Projects and which is usually on the left. Even if you are staring at your just-edited VBA code, clicking the save icon will not save your code unless it is also selected in the Project Explorer pane. You won't get feedback that anything was saved - but you can verify by checking the file timestamp in a separate window.
(2) if you have an *.xls file which (via the formula bar) refers to VBA functions from your *.xla / *.xlam file, then if you open the *.xls file without opening the .xla,.xlam file first, Excel may create external links to resolve the formulas (i.e. referring to a file which is not open). If you have moved or renamed the *.xla file you can get stuck with those "mangled formulas" and need to edit out the pathname links that Excel inserted using a global substitute. If you arrange to open the .xla,.xlam prior to any *.xls file that uses it, you shouldn't have a problem (e.g. by using the default folder).