Error 1004 SaveAs Method - Works 95% of the time.

kozelibe

New Member
Joined
Jan 31, 2007
Messages
23
Hello,

In general, the following lines of code work:

ActiveWorkbook.SaveAs Filename:=mstrBARRA_FILE_PATH & astrAccountName(intAccountCount) & "\" & _
astrAccountName(intAccountCount) & ".por", _
FileFormat:=-4158, CreateBackup:=False

or a slightly different line of code (-4158 vs. xlText...same thing)

ActiveWorkbook.SaveAs Filename:=mstrBARRA_FILE_PATH & astrAccountName(intAccountCount) & "\" & _
astrAccountName(intAccountCount) & ".por", _
FileFormat:=-xlText, CreateBackup:=False

The code loops through and saves several files on a network and works fine except for one account. When it saves one particular account it DOES actually save the file, but gives me the following error.

Run-time error '1004':
Method 'SaveAs' of object '_Workbook' failed

There is nothing unusual about the file or the file name. The data is slightly different, but is otherwise essentially the same as the other files. In all cases (each loop/account/file) the macro is saving over a file that existed from the previous day. I can manually resume next or I could create an error handler to do so. However, the former is annoying as I want the code to run when I'm in bed and the latter wouldn't be the best method for solving this problem.

Again, the code works, but gives me this error even though it did save the file.

This is driving me crazy.

Help!

Thanks,
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,214,891
Messages
6,122,101
Members
449,066
Latest member
Andyg666

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top