I have the following piece of cod, which is designed to obtain a file name and then save the excel file with the name. It works great until the user hits cancel. It then over saves the current file with the name false or returns the debugger. I want it to simply end if the user hits cancel but cannot find a way to do that.
Code:Sub SaveFile() ' If the locations of the cells containing the names changes please simply redefine the ranges attached to the variables Sheets("Info & Readings").Select UPSName = Range("A18") MtnceType = Range("AB7") 'maintaince type, Major or minor 'Address: 'Broken up into Street number, street, city, and province StNumb = Range("J9") StName = Range("N9") City = Range("T9") Prov = Range("Y9") MtnceWorkDate = Range("T4") If (UPSName = 0) Or (MtnceType = 0) Or (MtnceWorkDate = 0) Then MsgBox ("Please fill in required fields first: UPS Identification Name, Mtnce. Type, Address, and Mtnce. Work Date. Thank You") Else If (StNumb = "") Or (StName = "") Or (City = "") Or (Prov = "") Then MsgBox ("Please fill in required fields first: UPS Identification Name, Mtnce. Type, Address, and Mtnce. Work Date. Thank You") Else NomFichier = UPSName & " " & MtnceType & " " & " " & StNumb & " " & StName & " " & City & " " & Prov & " " & Format(Range("T4").Value, " yyyy-mmm-dd") & " .xls" ActiveWorkbook.SaveAs Filename:=Application.GetSaveAsFilename(NomFichier, FileFilter:="Fichier (*.xls), *.xls") End If End If End Sub




Reply With Quote
