0
votes

I have a Word macro that opens an XML file, makes some changes, saves and closes the file. The XML file exists but is definitely not open when the code gets to the point below. Just before the file opens I get an error message saying: "Run-time error '-2147024864 (80070020) The process cannot access the file -filename here- because it is being used by another process."

If I end the macro, close the .xml file and restart the macro I don't get the error message the second time. The error message pops up when the macro is at the code below.

Documents.Open FileName:=strInfoXMLName, ConfirmConversions:=False, Format:=wdOpenFormatText
1
Hard to say what the problem might be without showing your complete code (at least all lines related to opening/closing the file). Clearly the file is open and so throws that error, but it's impossible to tell why it's open from one line of code.Tim Williams
is definitely not open when the code gets to the point below. Inconsistencies cannot exist. When one appears to exist, check your premises. You'll find that at least one of them is mistaken.David Zemens
Thank You! for your advice. I only posted the line of code that opens the file because I thought there was a problem with that line of code. Per your suggestion to post the full code, I began to go through the code and extract only the parts that caused the problem. While I was doing that I only run a bare minimum section of the code and keep adding back all the many other lines of code until the problem showed up. By doing this I ended up getting rid of a lot of garage code that was causing problems. So, thanks again for suggesting that I examine the code and isolate the problem.user1218122

1 Answers

0
votes

Be sure to kill all instances of Word before running the sub. Also be sure to close documents and kill Word at end of sub.