SaveCopyAs error 1004

Jat999

New Member
Joined
May 7, 2016
Messages
49
Hi all

I am struggling with a runtime 1004 error with the routine below.

I want to save a copy of the current workbook into a sub folder. The code checks the sub directory exists and if not creates it. This works OK, Its the last line of the script that fails.

Any advice please.

Code:
Private Sub Save_Workbook()
 
Dim Wbook_Name As String
Dim New_Wbook_Name As String
Dim Cur_Path As String
Dim strPath As String
 
Wbook_Name = ThisWorkbook.Name
Cur_Path = ThisWorkbook.Path
strPath = Cur_Path & "\Archive"
        If Dir(strPath, vbDirectory) = "" Then
            MkDir strPath
        End If      
 
New_Wbook_Name = strPath & "\" & Now & "_" & Wbook_Name
ActiveWorkbook.SaveCopyAs Filename:=New_Wbook_Name
 
End Sub

Thanks in advance

John
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
The problem is that your New_Wbook_Name uses "Now", and that returns slashes in the date. You cannot use those in file names (it might actually confuse them with subdirectories).
You are going to need to format the Now portion, i.e. maybe something like this:
Code:
New_Wbook_Name = strPath & "" & [COLOR=#ff0000][B]Format(Now, "yyyymmdd_hhmmss")[/B][/COLOR] & "_" & Wbook_Name
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,320
Members
452,635
Latest member
laura12345

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