total newbie
total newbie

Reputation: 9

How do I get my macro to stop if i cancel save a copy

Greetings one and all - a christmas puzzle for anyone still looking at this site...This works but if i decide to cancel the process (ie not save a file and stop the process at this stage) it doesn't svae the file but the following marco (filltolastrow2) is still activated how can I stop this happening?

Public Sub SaveaCopyIncomeSheet()
    Dim file_name As Variant
    file_name = Application.GetSaveAsFilename("Overdue Report - Draft", filefilter:="Excel Files(*.xls),*.xls")
    If file_name <> False Then
       ActiveWorkbook.SaveAs Filename:=file_name
        MsgBox "File Saved!"
    End If
    filltolastrow2
End Sub 

Upvotes: 0

Views: 2698

Answers (2)

marg
marg

Reputation: 2827

Alternative:

Public Sub SaveaCopyIncomeSheet()
    Dim file_name As Variant
    file_name = Application.GetSaveAsFilename("Overdue Report - Draft", filefilter:="Excel Files(*.xls),*.xls")

    If file_name = False Then GoTo E_NoFileName

    ActiveWorkbook.SaveAs Filename:=file_name
    MsgBox "File Saved!"
    filltolastrow2

Exit Sub
E_NoFileName:
    MsgBox "File Not Saved"
End Sub

Upvotes: 0

Doc Brown
Doc Brown

Reputation: 20054

You possibly want

If file_name <> False Then
   ActiveWorkbook.SaveAs Filename:=file_name
   MsgBox "File Saved!"
   filltolastrow2
End If

Upvotes: 2

Related Questions