ESmith3187
New Member
- Joined
- Mar 22, 2017
- Messages
- 5
I am using an input box to allow a user to create a new file name. The code works well until the user returns to the process and errantly tries to re-create the same file name. When that occurs the Run-time error '1004" msg appears "Method 'Save As' of object'_Workbook' failed. Does anyone have any insight or prevention regarding this error?
The code is:
[CODE}
Sub XXCreateNewFileName()
Dim ThisMonth As String
Dim ThisYear As String
ThisMonth = Format(Date, "mmm")
ThisYear = Format(Date, "yyyy")
Application.DisplayAlerts = False
Dim FileName1 As String
Application.DisplayAlerts = False
FileName1 = InputBox("Please input filename", "Filename")
ChDir "E:\AAA\2017" & ThisMonth & "\ "
ActiveWorkbook.SaveAs Filename:="E:\AAA\2017" & ThisMonth & "\ " & FileName1 & "_XXX_YYY" & "_" & "ZZZ" & "_" & ThisMonth & "_" & ThisYear, FileFormat:=51, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
MsgBox "The name change was successful"
Application.DisplayAlerts = True
End Sub
[/CODE]
The code is:
[CODE}
Sub XXCreateNewFileName()
Dim ThisMonth As String
Dim ThisYear As String
ThisMonth = Format(Date, "mmm")
ThisYear = Format(Date, "yyyy")
Application.DisplayAlerts = False
Dim FileName1 As String
Application.DisplayAlerts = False
FileName1 = InputBox("Please input filename", "Filename")
ChDir "E:\AAA\2017" & ThisMonth & "\ "
ActiveWorkbook.SaveAs Filename:="E:\AAA\2017" & ThisMonth & "\ " & FileName1 & "_XXX_YYY" & "_" & "ZZZ" & "_" & ThisMonth & "_" & ThisYear, FileFormat:=51, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
MsgBox "The name change was successful"
Application.DisplayAlerts = True
End Sub
[/CODE]