Error on SaveAs Macro

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
 
K

Kevin

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top