PDA

View Full Version : Excel VBA SaveAs fails silently



Zeemu
11-29-2006, 09:11 PM
I've written a macro that uses the SaveAs function. The macro runs without error, but no file gets created. I tried running the same macro on a different machine and it works fine.

If anyone could shed light on what Excel/VBA/Windows/whatever settings might be causing this silent failure I'd be grateful.

Thanks.

Zack Barresse
11-29-2006, 09:34 PM
Hi there Zeemu, welcome to the board!!

First things first, we would need to see your code. Also, if you could describe your circumstances around your code and what you would like it to accomplish, that would be helpful.

Charlize
11-30-2006, 02:59 AM
It depends on your excel version how the saveas must be used. For example : in excel 2003 the thisworkbook.path isn't necessary to save a file to the directory of the workbook. In excel xp (2002) it is necessary to include the path or the save will not take place.
Instead of filename:=name for 2003
you must use filename:=thisworkbook.path & "\" & name for 2002.

Charlize

Zeemu
11-30-2006, 08:28 AM
I'm running 2003.

I'm new to VBA so I just wanted to get a handle for the various functions. When I went to try out SaveAs it didn't work as I expected. At first I thought it was the macro itself, but now I think it's a system or application setting that is interfering with the macro.

This is the test function I was using:



Sub Test()
ActiveSheet.SaveAs Filename:="c:\test.csv", FileFormat:=xlCSVWindows
End Sub


If I create a c:\test.csv manually first (e.g. using notepad) and then run the macro, I *don't* get the "File exists. Do you want to replace it?" prompt.

I've also tried dropping the macro security level to Low, to no avail.

Like I said, I think it's just something about this particular computer. I've copied and pasted the same macro into excel on two other machines and it's worked fine.