Debug: Run time error 1004 - "Method Save_AS Object' _Workbook' Failed

Ananthak275

Board Regular
Joined
Aug 22, 2020
Messages
128
Office Version
  1. 2013
Platform
  1. Windows
  2. MacOS
Can someone help me understand why my code is erroring out?
Workbooks.Add
Set wbk_syst = ActiveWorkbook
ActiveWorkbook.SaveAs "\\system " & Date & ".xlsx"
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Can someone help me understand why my code is erroring out?
Because "Date" returns the current date, probably with slashes in it, which are not valid to use in file names.
You will need to change the format of the date to something without slashes, i.e.
VBA Code:
ActiveWorkbook.SaveAs "\\system " & Format(Date,"yyyy-mm-dd") & ".xlsx"
 
Upvote 0
Because "Date" returns the current date, probably with slashes in it, which are not valid to use in file names.
You will need to change the format of the date to something without slashes, i.e.
VBA Code:
ActiveWorkbook.SaveAs "\\system " & Format(Date,"yyyy-mm-dd") & ".xlsx"
I have 3 different saveAS new files. For the first file, it worked without any issue. But when it was the second, it errors out as "Document not saved"
 
Upvote 0
Are you trying to save them directly in the "system" folder?
If so, you need another slash after "system", i.e.
VBA Code:
ActiveWorkbook.SaveAs "\\system\" & Format(Date,"yyyy-mm-dd") & ".xlsx"

Also, are you giving all 3 files the same name (the date)?
If so, they would just overwrite each other, but if you didn't close the first one, the other two wouldn't work, because you cannot overwrite an open file.
 
Upvote 0
Are you trying to save them directly in the "system" folder?
If so, you need another slash after "system", i.e.
VBA Code:
ActiveWorkbook.SaveAs "\\system\" & Format(Date,"yyyy-mm-dd") & ".xlsx"

Also, are you giving all 3 files the same name (the date)?
If so, they would just overwrite each other, but if you didn't close the first one, the other two wouldn't work, because you cannot overwrite an open file.
Workbooks.Add
Set wbk_syst = ActiveWorkbook
ActiveWorkbook.SaveAs "\\system " & Format(Date, "yyyy-mm-dd") & ".xlsx"

Workbooks.Add
Set wbk_doc = ActiveWorkbook
ActiveWorkbook.SaveAs "\\documents " & Format(Date, "yyyy-mm-dd") & ".xlsx"
This is how my code is set up currently, one runs after the other. System files gets saved correctly but documents errors out as "Error 1004: Document not saved"
 
Upvote 0
What is the exact folder name and file names that you are trying to save these files to?
Is "system" and "documents" supposed to be folders, or the beginning of file names?
 
Upvote 0
What is the exact folder name and file names that you are trying to save these files to?
Is "system" and "documents" supposed to be folders, or the beginning of file names?
I didn't use the full file name due to privacy issues.
Set wbk_doc = ActiveWorkbook
ActiveWorkbook.SaveAs "\\Extract - documents " & Format(Date, "yyyy-mm-dd") & ".xlsx"
a bit more snip of the original code. Extract is the Folder, and Documents is the start of the file name.
 
Upvote 0
You need a slash after the last folder name and before the start of the file name, i.e.
Excel Formula:
ActiveWorkbook.SaveAs "\\Extract\documents " & Format(Date, "yyyy-mm-dd") & ".xlsx"
 
Upvote 0
You need a slash after the last folder name and before the start of the file name, i.e.
Excel Formula:
ActiveWorkbook.SaveAs "\\Extract\documents " & Format(Date, "yyyy-mm-dd") & ".xlsx"
It's still erroring out as "Document not Saved" is there a different way of writing this?
 
Upvote 0
You need a slash after the last folder name and before the start of the file name, i.e.
Excel Formula:
ActiveWorkbook.SaveAs "\\Extract\documents " & Format(Date, "yyyy-mm-dd") & ".xlsx"
Workbooks.Add
Set wbk_syst = ActiveWorkbook
ActiveWorkbook.SaveAs "\\yExtract\system " & Format(Date, "yyyy-mm-dd") & ".xlsx"

Workbooks.Add
Set wbk_doc = ActiveWorkbook
ActiveWorkbook.SaveAs "\\yExtract\documents " & Format(Date, "yyyy-mm-dd") & ".xlsx"

Workbooks.Add
Set wbk_doc = ActiveWorkbook
ActiveWorkbook.SaveAs "\\yExtract\optimization " & Format(Date, "yyyy-mm-dd") & ".xlsx"
Only the first file will save. In this situation both Documents error out "Error 1004: Document Not Saved"
 
Upvote 0

Forum statistics

Threads
1,215,507
Messages
6,125,212
Members
449,214
Latest member
mr_ordinaryboy

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