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

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

Related

How to change the "fullpath" property of References in VBA (Tools -> Refences)?

I'm sure that there are different ways to phrase this question, but that is the end result that I want to achieve.
So, I have a setup where code is written in C# and added as functions to Excel. It relies on having a specific .tlb file in the Tools->References that can be found in the VBA window.
While I was testing this, the .tlb file (and the rest of them) was on my local drive, but now that the project is working, I need to transfer it to a network drive. The problem is that I can't find any way to change the actual file (or filepath) that is being referenced - it's always looking at my local path.
I've tried a few things:
Followed the steps listed here https://support.microsoft.com/en-us/help/308340/how-to-check-and-remove-incorrect-project-references-in-the-visual-bas
Tried several VBA codes using the .References.Remove expression. This does not actually remove the reference from the list, it only unticks it.
I've tried to remove the file from my local drive (causing an Excel error that a reference has been moved, deleted or renamed - good) and then add a reference from the new location that I want. This resulted in one of two things:
1) If I try to add it manually - nothing happens, the existing reference remains unticked and nothing new is added (that I know of).
2) If I try to do it via .References.AddFromFile "filepath" expression it ticks the reference, if it was unticked (this does not make the external formulas work), or an error that a reference with such a name already exists, if it was ticked.
Recompile on the network drive with the following silly way.
Open the VBA editor
Go into each module
Insert a line (doesn't matter what you write)
Press ENTER
Remove the line that you've inserted
When finished, in the menu click Debug \ Compile
Source: by Andreas Killer
https://answers.microsoft.com/en-us/msoffice/forum/all/ms-excel-error-cannot-run-the-macro-the-macros-may/3f3106b2-ae60-4d21-ac94-67e54e605922

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.

Open Excel File from Command Line Unprotected View

I frequently open large excel files (100 MB+) from a network location that I completely trust. However, the default trusted domains on the workstation that I use does not include files on the network drive. It is cumbersome to load each excel file twice (once to open it from explorer, then again to 'enable editing', i.e. remove protected view).
Is there an argument/switch that can be provided to excel.exe from the command line that will force a file to be opened in unprotected(editable) view? I would find this less cumbersome than waiting for a large file to load twice.
I typically use Excel 2010 and 2013.
Note: I already know how to disable protected view through the excel interface, this is not the solution I am looking for, as these settings reset to their defaults everytime I log off the workstation.
I am also prepared to accept the fact that this might not be possible to do except in the Excel GUI. But if anyone has a workable solution, that would be brilliant. Thank you!
Is there an argument/switch that can be provided to excel.exe from the command line that will force a file to be opened in unprotected(editable) view?
No.
The protected view comes as a result of the level in the security settings, thus it would be a major security problem, if it can be avoided.
As a possible workaround - copy the files to your computer, mark it as trusted and open them there.

Excel file retrieve original file extension or bypass fileformat-extension mismatch

We have a file that gets imported by a macro to extend Excel's macros functionality. This file has an extension .dll. The person who originally made this purposely changed the extension to dll to make it a bit less easy for users to just open it. All was well, but now the latest excel 2016 update gives an error "file format and extension mismatch".
which is correct. Now, in my opinion, I have 2 options.
change the extension to what it originally was (which I don't know).
bypass the extension/file format mismatch (which I don't know how to do and might pose a security risk).
I tried the following extensions: xla,xlam,xlsx,xlsb,xlm,xls,xll. but still get the same message.
Does anyone have a clue on how I can find out what the original file extension was?
I am not sure but the file might have been created in excel 2000 or 2007.
I found out that the issue is not with extension or file format but the problem was caused by AV/bit Defender which saw the file as a zip file started scanning inside and removed a single file inside thus causing excel to no longer recognise it as a valid file.
I noticed some weird behaviour as soon as I restored quite some files from backup, AV defender started using 95% cpu. after that I went into the logs and noticed defender thinks it is a trojan.
Thanks all for your input!

.xlsm file open as read-only

No doubt a very easy fix that someone here has come across before...
I have an Excel macro enabled file (.xlsm) that has some VBA to make graphs, pick data, get data, scale axes etcetera however 75% of the time when I open the file it says that another user has the file open and will be read only.
I've checked very carefully and I'm definitely the only user with the file open. The same thing occurs if the file is located either on the hard drive of this computer or if I load it from a server.
If the file is saved as a .xls file the problem never occurs, up to date at least.
Adding "End" to the VBA code seemingly has no effect.
I can only assume from my above tests that it is something in the VBA part of the file that causes this issue. Any help would be much appreciated.
Some thought:
1) Check your code to see if at any point, you have the file open (workbook.open to current file)
2) Is the file on a network?
3) Check the .xlsm's properity if it is read-only
4) Go to Option - Trust Center - Trust Center setting to see if macro is enabled.
These are Excel settings for the computer. If you go to the File tab on the ribbon, Excel options and go to Trust Center > Trust Center Settings you can modify this.
You can set the trusted locations documents or publishers. Also check macro settings and protection.

Resources