Excel wants to save an open file to another filename in VBA script

B

BPoppe

Hi,
I'm having a real strange problem here which I really want to be solved.

An XLS file with VBA code is used to update some other XLS files (with and
without VBA). At a certain moment, the VBA script for updating wants to save
the open XLS file. This has been going on for years without a problem, but
now, since last week, a save dialog comes up suggesting a random name. When I
click "cancel", the following message comes up:
"Run-time error 1004: Your changes could not be saved to '(filename)', but
were saved to a temporary document 'C5879400'. Close the existing document "
and so on.

What I tried to solve this:
* Try it on another system with the same version of Excel on it (Excel 2002
SP 3), there it works.
* Removing the temporary files from the C:\Documents and
Settings\(username)\Local Settings\Temp directory. This solves the issue -
sometimes.

The code exerpt where it happens:
Windows("(filename)").Activate
Range("A1").Select
Sheets("(sheetname)").Select
Cells(1, 248) = Finperfact
Columns("A:DG").Select
Selection.Columns.AutoFit
Range("C2").Select
Application.Run "(filename)!(methodname1)"
Application.Run "(filename)!(methodname2)"
Application.Run "(filename)!(methodname3)"
Application.Run "(filename)!(methodname4)"
ActiveWorkbook.Save

(filename), (sheetname) and (methodnameX) are just used to obfuscate the
code and are, of course, not written like that in the real source code.
The error occurs on executing ActiveWorkbook.Save.

The lines before ActiveWorkbook.Save run some VBA code in the file that will
be saved by ActiveWorkbook.Save. While this might have to do something with
the problem (a lock being set while executing, I don't know) but it has been
working for years like this, so I'm not sure at all.

Since on other workstations the problem doesn't occur, I guess it has to do
something with certain settings in the OS or in Excel. But as the system on
which the problem occurs fulfills the role of a file server, just switching
workstations is not an option. Does anybody have any suggestion?

Kind regards and thanks in advance,
Bart Poppe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top