Error on SaveAs Macro

  • Thread starter Thread starter Kevin
  • Start date Start date
K

Kevin

I got this code from this forum and use it on a spread sheet, it works fine
in till you save a second time and then it ask "A file.... by this name
already exits, do you want to save it?" if I choose OK then the macro works
fine, but if I choose NO or Cancel then I get an error "Run time error 1004;
Method 'Saveas' of Object_Workbook failed". Is not really that important but
I would like it to just to work right! It does what it supposed to do except
for the annoying message!

Thank for your help in advance
Kevin Brenner

Sub SaveNowDate()
Dim wb As Workbook
Dim strdate As String
strdate = Format(Now, "mm-dd-yyyy")
Set wb = ActiveWorkbook
With wb
.SaveAs Sheets(1).Range("F3").Value _
& " " & strdate & ".xls"
End With
Cancel = True
End Sub
 
I was able to find a solution may not be the correct one but it seems to
work. I added a line "On Error Resume Next"

Sub SaveNowDate()
Dim wb As Workbook
Dim strdate As String
strdate = Format(Now, "mm-dd-yyyy")
Set wb = ActiveWorkbook
With wb
On Error Resume Next
.SaveAs Sheets(2).Range("g1").Value _
& " " & strdate & ".xls"
End With
Cancel = True
End Sub
 
Back
Top