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

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,422
Office Version
  1. 2016
Platform
  1. Windows
Can anyone offer any advice as to why the following code randomly generates a run time error 1004, 'Method 'SaveAs' of object '_Workbook' failed'?

I've read various bits on the internet, none of which seem to apply here, (for example the workbook is not on a shared or mapped drive).

If there is no obvious solution, is there a way I can ignore this particular error? (I know that I could ignore all errors but I just want to ignore this particular one if that is the only option).

Code:
DestFile.SaveAs fileName:=ThisWorkbook.path & "\ST Files\System Files\" & "Raw Data (For Import) - " & Sheet8.Range("B1").Value & " " & Sheet8.Range("B5").Value & " (" & Sheet8.Range("F3").Value & ")" & ".xlsx"
 
Last edited:

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Best guess is that one of the cells you are using to create the file name, sometimes contains an invalid character.
If you do something like
Code:
Dim Fname As String
Fname = ThisWorkbook.Path & "\ST Files\System Files\Raw Data (For Import) - " & Sheet8.Range("B1").Value & " " & Sheet8.Range("B5").Value & " (" & Sheet8.Range("F3").Value & ").xlsx"
DestFile.SaveAs Fname, 51
Then it's easier to see what the complete filename is when you get the error.
 
Upvote 0
You're welcome

You can also build in an error handler, something like
Code:
Dim Fname As String
Fname = ThisWorkbook.Path & "\ST Files\System Files\Raw Data (For Import) - " & Sheet8.Range("B1").Value & " " & Sheet8.Range("B5").Value & " (" & Sheet8.Range("F3").Value & ").xlsx"
On Error GoTo Oops
DestFile.SaveAs Fname, 51
On Error GoTo 0

Exit Sub
Oops:
   MsgBox "File not saved " & vbLf & Fname
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,021
Latest member
Justyna P

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