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.
Related
I am working with openpyxl to make changes to a file and then save it.
Among the lines that are used to this, the one that gives me trouble is:
wb = openpyxl.load_workbook(filename=sheet_loc, read_only=False,keep_vba=True)
I know for a fact that the "keep_vba" is a very dangerous parameter, because if you call it True when you are saving a .xlsx file, the file will get corrupted. And vice versa.
Now, this is exatcly what happened to me. I had a .xlsx file and I wrote "keep_vba=True", so the workbook is corrupted. This is what I receive when I'm trying to open it:
My question is: Is there any way to fix that ? To recover this sheet ? I've tried "Open and repair" button, but it didn't work, it just gives me the same error said above.
I was having this same problem and I got the solution today.
To clarify, what you did here with openpyxl was nothing more than "turning" vba on for this workbook, but since the workbook still is a .xlsx file, it does not support this kind of thing.
To recover this file, you just have to change the type of the file to .xlsm, you can do this on windows by simply renaming it from "workbook.xlsx" to "workbook.xlsm".
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
Problem with VBA - workbooks.open. I can't open two files simultaneously.
Hi,
Maybe it's simply the way it's supposed to be, but it seems strange to me. My macro works fine as long as I open only one file in the background using workbooks.open. But when I'm opening the second file, then the first one just closes. Is it normal?
Nothing very complicated. First i Open database:
Set database = Workbooks.Open(Filename:="Y:\EME\LW\PL-PIA\AIR\AIRFREIGHT\Zlecenia transportowe\baza_danych_transp.xlsm", ReadOnly:=True)
Then, when I open CMR, the database switches off.
Set CMR = Workbooks.Open("Y:\EME\LW\PL-PIA\AIR\AIRFREIGHT\Zlecenia transportowe\CMR_bis.xlsm")
Do I need to create a new instance of excel application for this?
I'm sorry, but I think I know what was causing the problem... I had a macro embedded in CMR that on opening of the workbook was getting some data from database and then was closing it. I dead forgot about it... Thanks for help, switching the names of the worbooks did remind me about it...
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.
Recently a large number of security updates were pushed for Microsoft Office at work. We have an Excel tool with a Visual Basic backbone which worked prior to the updates, and now does not work.
I have done some isolated testing and have found that we see the same 'error 75' when using the FileCopy method on .BAT and .EXE files. Other less 'risky' file types seem to be ok. This is also an issue with the 'Open' command.
Does anybody know of a workaround for this issue when copy/pasting .EXE and .BAT files, or maybe this is a known issue with a certain security update? I have searched everywhere, but the Google is failing me. I am hoping either:
Someone knows which security update is the culprit and I can try
uninstalling it to see if that fixes the issue
There is a different way to copy/open/manipulate .BAT and .EXE files that doesn't violate the new security patch.
Some background:
We are using Microsoft Office Professional Plus 2010 and the tool uses Excel as the interface.
Here is the testing code I am using. I have verified that .TXT and .DAT files run just fine while .EXE and .BAT files cause 'error 75' indicating a permissions error. And before you ask, yes, the file path is correct, I have just omitted my employee identification information.
Sub Macro1()
' Declare variables
Dim Filename, SourcePath, DestPath As String
' Pathname variables
Filename = "test.dat"
SourcePath = "C:\Users\<REDACTED>\Desktop\working_copy\" & Filename
DestPath = "C:\Users\<REDACTED>\Desktop\working_copy\test\" & Filename
' Copy file from Source and paste in Destination
FileCopy SourcePath, DestPath
End Sub
Here is an image with the updates that were installed. The tool worked prior to the 6/14/2017 dump, so anything before can be disregarded.
Sorry for the image, too many to enter them manually, no easy way to copy from the update list:
MS Office 2010 Security Updates
Nothing with the tool or file structure changed. The only thing different is the updates. Also, we tested the same tool with Microsoft Office Home 2016 and it worked without a hitch.
Any and all help will be appreciated. Thanks in advance!
While I never found a real fix for this issue, I did come up with a slightly 'hacky' work-around.
The MS security patch prevented me from copy/pasting .BAT and .EXE files, I but could still save .BAT files.
So, I ended up having my script create a text file called "copyExe.txt" which had a single line:
ECHO F|xcopy <source> <destination>
This was then renamed to be "copyExe.bat" and run.
By creating a .txt file, I circumvented the errors when using the VBA Open function on .BAT files (so I could actually create this new batch file). This batch file has the sole purpose of copy/pasting a .EXE file from one folder to another, which circumvented errors when trying to copy/paste .EXE files.
After the copy/paste script is run, it is deleted.
All-in-all it feels like a very silly solution, but it works and is very non-invasive for the user.