Excel Crashes When Accessing .xlam File - excel

I use an XLAM file to store a few subs for general spreadsheet purposes. The XLAM is added and checked in the VBA editor's references and has worked for 4+ months without any issues. Most of the functions are pretty basic, like creating PDF's or refreshing connections in whatever spreadsheet calls the subs that reside in the XLAM file.
A few days ago, none of my morning processes ran, and when I checked what happened I had 10 "recovered" files which, when I went to check repairs, Excel said there was nothing wrong with them. I tried to step through the subs to see where they failed, but each one crashed without an error message from VBA, they just failed completely. I tried running the macros through a vbs file called from Powershell and I received the message "The remote procedure call failed" on the line which called the macro.
I did not change any code in any of my workbooks or in the XLAM file, nor did I change the references to the XLAM in any way. In addition, the code consistently works on my co-worker's machines.
I've been calling the functions from the XLAM file as follows:
Call Project.Module.Function/Sub(argument)
Maybe it is an issue with the RPC but I really do not know, any help would be greatly appreciated, and I'm happy to post more code.

Related

Excel VBA macro failing to save workbook on coworker's computer, but fine on mine

I'm encountering an issue trying to get some macros and VBA scripts working on a new coworker's computer. I've been using the same code for years on my machine and several others without issue, but when my new analyst tries to run it, it throws an error stating it couldn't save the file. He can manually save the file without issue, but running the script throws the error. The really weird part is that it lists the file path, but replaces the filename with a seemingly random hex byte.
On another file, if he opens it, closes with or without saving, then I open the file and try to save it using a macro, it fails saying "cannot access file...". If I copy and paste the file, open and run the macro again, it saves over the offending file no problem.
We've checked permissions and settings and haven't found anything that was different between the two systems. We're both on VMs. His hardware allowance is less than mine but otherwise they're both IT-managed and identical. I'm at my wits' end... Any advice on what may be the source of my grief would be helpful, even if not a solution.
A couple of things I'd check before trying to step through debugger mode.
Coworker does not have write access to the directory (I think you said you checked already)
The new users' Trust Center Settings are not correct
File > Options > Trust Center > Trust Center Settings... > Macro Settings > Ensure the box is checked to trust the VBA model and that macros are not disabled
The new user does not have the same libraries referenced.
Alt + F11 > Tools > References... > Check if coworkers' libs match yours
Is he using a new/different version of Excel that you? A lot of older code got bojangled when Office 365 hit the scene.
After checking settings, I would ask the following:
What error is thrown when coworker attempts to run the macro?
When does the error get thrown? It could be that you have code that is attempting to edit the file (or has another file stuck in an edit) at the same time you're trying to save it.
I would see why the file name is getting corrupted. It sounds like coworkers' machine is looking to a bit of memory or memory address that is somehow getting forgotten. Like the code is referencing a variable that is out of scope.
User Access Control has been enabled on his VM that is somehow preventing him from saving the file correctly.
Your code does not properly Quit the Excel application, so its still running in the background on coworkers' machine. Have them open/close without saving a file and check Task Manager to see if Excel is still up to confirm

Workbook opening on a network with "corrupt" macros

A colleague is trying to open an .xlsm book from a network folder but gets this message:
The visual basic for applications (VBA) macros for this workbook are corrupted and have been deleted. The corruption most likely exists in the current file. To recover the macros, open up a backup copy of this file if you have one.
If they download and save the file from an e-mail then open it locally it works fine.
Other people can also open this book from the network and it works fine.
In the failing book, it appears that all objects (worksheets and modules) have been duplicated with a 1 suffix.
Searching this issue online I found several suggestions but none of them seem to fit this scenario.

Excel hangs/crashes while updating external link at file opening

I encountered this weird ass and funny error.
I built a file for data ETL. This one takes in various .csv files, combines them and export new .csv files using VBA. The file is originally named as "xxx Modelling ETL.xlsm". It could be opened normally till one day it hangs or crashes while trying to recalculating something (may be the underground query).
After hours of struggling, I opened the file as a copy (under a new name of Copy of ...). Strangely it ran smoothly, no crash or hang. Then I try rename it by remove the "Copy of" part, then the error occurs again.
I want to share this as there could be someone has the same problem, or someone who could shed some light on this black magic thing.
Some solutions:
Rename the file or move it to local drive instead of Onedrive makes thing works normally again.
Open Trust Center, disable Macro with notification, Trusted Locations, and Trusted Documents. Enable them for specific files when open, not for all.

Add-in macro conflict Excel

Initially I have 1 function: CusFun in an Add-in1
I copy all code in Add-in1 into module in Excel file, save file 1.xlsm
I open 1.xlsm to work, now I have 2 functions CusFun
I changed the name (and only the name) of the functions in macro in module1 in 1.xlsm as CusFun_Port
Now I have 2 UDF: CusFun and CusFun_Port when I work with 1.xlsm
But CusFun_Port (all of them) always return blank while CusFun work normally.
Why use macro-enabled file instead of add-in? Because I need to send the file to many users back and forth. I initially thought only I use them, using add-in save me the trouble of clicking "Enable content". With add-in, every computer use it must install it. And when the file is sent to another computer, all the custom functions in the file must be re-targeted to that computer's add-in location. My users are not proficient in any of those tasks. And those tasks takes far more time than clicking "Enable content".
What can I do to make sure that both functions in add-in and file-specific macro work?
Finally, I found it. Because I change only the name at the top of the function, it doesn't work. Because all of them are recursive, the function's name inside did not change, hence it doesn't work. There is no conflict here.

Run-time Error '1004' - Method 'Open' of object 'Workbooks' failed

OK, so far I've uninstalled & re installed Office-2010 3 to 4 times, done hours of research for 3 days with no success. I started getting this error either from Vbscript or Excel VBA, performing the same command that has worked for months. I am not sure what I may have changed, I don't recall changing anything that could cause it but I nailed it down to the ReadOnly:=True parameter. I think something may be wrong with the registry... but re-installing should fix it right? It didn't...
Anyways, very simple command that I recorded on Excel 2010. This command WORKS FINE and the file opens:
Sub Macro1()
Workbooks.Open Filename:="C:\temp\file_9928_131101.xlsx"
End Sub
But when I add the ReadOnly:=True parameter, it does NOT WORK:
Sub Macro1()
Workbooks.Open Filename:="C:\temp\file_9928_131101.xlsx", ReadOnly:=True
End Sub
This is the returned error Run-time error '1004' Method 'Open' of object 'Workbooks' failed:
When I click Debug, the error is at the only line of code.
The file is corrupted. Resave it with another name and change the name in the function. Try that it works and after that rename the file as you want to call it.
It worked for me and I had a corrupted file. The read only shouldn't be a problem.
Putting an answer here for others like myself who have this issue and the normal solutions don't work.
Another potential cause of this is corrupted temporary files. I think it may only apply if the file you are trying to open is on a network drive or other remote host.
Anyway, try wiping your temp folder (as in the one you get to if you type %temp% into Windows Explorer) then restarting the computer.
I have had the same issue with an Access file stored in a local OneDrive folder, referencing an Excel file stored in the same local OneDrive folder. The solution was to move all files into a "static" (i.e., not synchronized, not OneDrive) folder.
Thought that this specific case/application might help someone.
I realise this is late but if you want to open & repair a corrupted workbook automatically use:
Set oWB = Workbooks.Open(Filename:="C:\my\file\path.xlsx", CorruptLoad:=XlCorruptLoad.xlRepairFile)
If you are downloading the file from some external source (eg- email), just open the file directly from the email and then save the file. Try opening the file in macro ...hope it works...it worked for me....:)
I had a rogue excel process that was running in the background. When I killed it from the task manager the code worked. I hope this helps.
I was too, going crazy with Workbook.Open function, getting the weird Open fail error for no obvious reason. My code also did some some copy-pasting after Open function, which seemed to trigger it.
Eventually I found out that turning ScreenUpdating OFF seemed to cause this - keeping ScreenUpdating ON, made things click for me (maybe someone finds this helpful in the future). I'm one of those who tends to switch ScreenUpdating off for all code whenever possible.
Application.ScreenUpdating = False
I know I'm answering late on this, but I resolved a similar issue (same error but running excel from a .Net app) by making sure VBA was installed correctly on the target machine.
Control Panel->Programs and Features->Uninstall a Program... find your Office install, Right-click and select "change" ->Add Remove Features->Office Shared Features->Visual Basic for Applications->Run From My Computer
This did it for me.

Resources