View removed VBA code after repair of Excel file - excel

I am getting an error when opening excel: We found a problem with some content in XXX. Do you want us to try and recover as much as we can? if you trust he source of this workbook, click Yes."
clicking Yes, "fixes" the issue but deletes a lot of VBA code, two weeks worth.
Whatever the issue it was introduced yesterday, I do not want to redo two weeks worth of coding. Is there anyway I can view what was removed, or open the VBA in notepad++ or something without opening the excel?

I opened another excel workbook and tried all the different options for the argument XlCorruptLoad in the Workbooks.Open to open the corrupt workbook. I noticed that there were two non existing sheets created in the project explroer of the corrupt workbook that had the code in there. I am not sure if it did that s a result of what I did or it was there all along and I did not notice it
Note that the reason I had a corrupted data is because the code was extracting a list and putting it in a cell validation formula..i guess I overloaded it.

Related

Can't save macro-enabled workbook on remote server after a macro has run

My macro-enabled workbook has been working fine until recently. It runs fine on my local drive, but no longer saves itself when run from a remote folder. I suspect some recent updates on the server are to blame.
If I open the workbook and press the save button, a pop-up appears with a progress bar for a second or two. This has not happened before, but the pop-up does close and allow me to continue.
When I run the macro in the workbook, the last line is ThisWorkbook.Save. The same pop-up appears and hangs. If I close the pop-up and press the save button, it also hangs now. If I choose File> SaveAs, all I get is a blank page with no folders to choose from.
I have a workaround to copy the workbook to a local folder, run the macro, then copy it back to the remote drive, but this may be difficult for my users to handle.
I made a new workbook with a macro that only calls ThisWorkbook.Save from a single button, and this works fine. The problematic workbook gets data from csv files and copies it into itself. Maybe this is causing a problem? Maybe the macros are too large for the anti-malware software to handle?
Does anyone know what recent changes have been made to Server that would cause my old macro to hang on saving?
I got the macro working, but not sure why.
The problem arose with an inefficient way to merge data from two sheets together. I had been using Find, and changed it to march through the data row by row instead. The saving window still pops up, but only for a second.
I don't know exactly why the old method prevented the workbook from being saved. The main difference is that the Find method uses objects, while the method I changed it to use integers and compare cell contents with an if statement. Maybe the memory was being filled with orphaned objects? I don't see what difference that should make when saving the file. The data in the sheets being saved is the same.
If anyone knows what difference this would make in saving a workbook, please add and answer or comment for posterity. It might help someone with a similar problem.

Microsoft Excel keeps repairing my .xlsm file for no apparent reason and eliminates data validations on a sheet

I recently created an automated Excel utility (using Microsoft Office 2019), in which I've extensively used data validations, VBA code, named ranges and formatting. It was working well until one day I received an Excel prompt message that read:
When I click on Yes, it gives me another pop-up where it says it recovered the file, and also gives me a link to the error log XML file. I click on it and open the .xml file using my default browser, and it shows the following details:
Looks like it is removing data validations from a particular sheet, and I realize that is true when I navigate to that sheet in the UI. To work around this unwarranted and repeated data-validation removal that Excel application is enforcing, I created a macro code that will re-instate all these data validations as required. The real problem arises when this Excel file is opened on a different computer with Microsoft Office 365. Looks like it is removing not just data-validations but also other components like named ranges and buttons. There could be other things that it might be removing, which I am unaware of at the moment. So the macro created to re-instate the data-validations is no longer useful.
Why does this problem arise? And why is different version of Excel behaving differently? How do I solve this? Appreciate your kind help. Thank you!
As rightly suggested by Ron Rosenfeld and e_conomics, the issue was with the data validation lists, whose sources were strings of comma separated values that were going beyond 255 characters. Apparently, that is a limitation with Excel.
When I replaced the sources of data validation lists (string of comma separated values) with the ranges containing the corresponding values, the problem resolved itself. The repair dialogue never appeared again.

Excel Formula is not referencing properly - formula is modifying

Background information -
I have a macro-enabled workbook that interacts with SQL. After some cleaning steps are completed, it eventually runs an elongated list of Stored Procedures and pastes them in an external workbook. It has been working fine up until recently where many of the formulas that reference other tabs in the template are randomly having issues finding the reference...thus changes the formula. I have absolutely no idea how this is occurring.
Formula example:
=IF('16.17.A.SupCarrier'!U9="","",'16.17.A.SupCarrier'!U9)
Formula changes to:
=IF(['16.17.A.SupCarrier']'16.17.A!U9="","",['16.17.A.SupCarrier']'16.17.A!U9)
For what it is worth.....I found a "solution" to the problem. I was previously saving the document while another excel sheet was open which I assume could have been causing memory issues preventing it from saving properly. I saved this document without any other Microsoft apps open and the issue seemed to resolve itself without modifying any formulas.

Excel Workbook freezes after saving it on Excel 2013

I am developing an excel "application" that will be distributed to a few users, so it has a lot of macros/vba code on it. The workbook is about 2MB right now, so it's not incredibly big.
I was developing it on excel 2013, however my workstation had a problem and I had to work on it from a computer with excel 2010 for about a week. Problem is, when I came back to excel 2013, whenever I try to save the workbook(on excel 2013) it immediatly stops responding. When the program closes, excel is never able to recover anything and says the file is corrupted. The problem simply does not occur on excel 2010, where everything works perfecly and I can save it OK.
Does anyone have any idea what might be causing this? I have tried removing a few sheets and saving the workbook afterwards, to test if a specific sheet was corrupted/causing problems, but even after I remove all the sheets from my woorkbook (and just leave a new blank sheet on it) it still freezes when I try saving.
It's important to note that the workbook in question uses a lot of excel features, meaning it has conditional formatting, defined names, activeX controls, shapes, formulas etc.
Well, I did what Ralph suggested and created a new excel file, then copied everything from the old workbook to the new one. Now it works fine. Apparently that was my only way out, the file was probably corrupted in some way.

Excel Error: Removed Records: Sorting from /xl/worksheets/sheet10.xml part

I'm almost sure I will have to create a new excel file, but maybe at least here I get some ideas what was the source of the problem.
My excel file is constantly giving the following error:
Excel found unreadable content in 'filename.xlsm'. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes.
So I do. And the file opens as repaired showing:
Removed Records: Sorting from /xl/worksheets/sheet10.xml part.
The detail is that I don't even have a sheet10
Its a big excel file full of custom-objects. But I have no DB connections or autofilter so could not relate to AutoFilter Criteria Using Array (Error) - Too Large String? or xlsx error: "Removed Records: Named range from /xl/workbook.xml part" when tried to resolve errors.
Anyone has a clue what's going on?
tks in advance
try clearing the sort before saving down the workbook. When this happened to me I had my sheet references mixed up so the sort wasn't cleared
Sheets(yoursheetname).Sort.SortFields.Clear
I am afraid I cannot explain what is going on, but I had similar experience several times - always with XLSM file. In the latest case I learnt that Excel did not like the same range name used twice, when defined as Worksheet range name (we assumed it is safe to use it that way).
Our troubleshooting path is:
try to save file as XLSB (binary macro file) and either use XLSB file or save it back to XLSM
check file history (we always keep daily snapshots) and find when the problem firstly occurred; use previous version and port your changes
extract the code (via SVN code), create a new workbook and import the code back
Usually Step 1 solves the problem, but Step 3 never failed us.
Awesome,
This issue has been driving me crazy!
It seems that saving as the xlsb (binary) file PLUS adding the clearing of sort fields appears to have sorted out my issue.
I added the following code to the BeforeClose sub, it appears to clear the fields really quick, changes to my Dashboard and prompts for saving.
The xlsb file saved over a mb in file size and appears to load a little quicker!
Thanks for the pointers & support!
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim Sht As Worksheet
' Clear all Sort Fields prior to Save & Exit
For Each Sht In Application.Worksheets
Sht.Sort.SortFields.Clear
Next Sht
aa1_Dashboard1.Select
aa1_Dashboard1.Activate
End Sub
I would like to add my own confirmation regarding clearing sort fields in your spreadsheet, as first suggested by Chris. I specifically had the error occur after I used column sorting in a VBA macro, so I deduced that the problem must be column/field-Sort related. It was.
Adding the line:
Sheets(yoursheetname).Sort.SortFields.Clear
after the sort command allowed the sorted columns to remain sorted (in my case), but cleared whatever was causing the
"Sorting from /xl/worksheets/sheet10.xml part." error when the file was next opened.
Many thanks for your support.
I don't know if this will help anyone but it's solved my problem. I had an excel sheet, nothing complex, just contacts, a much used file in Excel 2010 on Win7. Today I was using the 'filter' to select specific groups to email targeted content to. In the middle of selecting and copying to paste into Outlook, the document came up with a pop up as if I was installing something, then the 'installer' both of which I cancelled out of. The Document closed and then on trying to reopen, I was getting the error message. If I chose 'yes' to repair I was given just the subset of my filtered list, so about 40 of my 350 records, the rest lost. I googled and tried different things, including opening in Googledocs google sheets and nothing worked. I never 'saved' the repaired version as my old data wasn't in that. Just now, I right clicked on my document in explorer and chose "restore previous versions" and it brought me to the version of yesterday - thankfully, nothing added to it since then. Opened that one and bingo, it opened fine with ALL the data in it. I know the filter had corrupted it, so will be cautious next time I use it. I don't know why it doesn't like the filter but 4 hours on, i can now calm down and relax! Hope this helps someone.
was having this issue as well. I have a spreadsheet with multiple tabs (maybe 30 tabs?) and had filters on each sheet, and shared on SharedPoint. The error was not enabling editing of the file on SharePoint. I removed the filters on every sheet and uploaded back to SharePoint and the issue is gone!
I did what Chris mentioned above. Clear the sort fields in your spreadsheet.
Sheets(yoursheetname).Sort.SortFields.Clear
Also, save the file as *.xlsb.
That should get it to work.
When you get a message telling that Excel found unreadable.... just click "Open" and then close all the following messages you get.
-In the VBE open the project showing the name of Addin or the .xlsm.. the click anywhere in any module of the workbook as you are going to edit the text of the macro, then click save, select workbook type like Addin select the folder where you want to save it, give it a new name then click "Save", that is all you have to do, the new file you created will ok.

Resources