ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   SaveAs (https://www.excelbanter.com/excel-programming/408589-saveas.html)

blerman

SaveAs
 
I have created the following macro, which is supposed to save the file based
on values in specific cells and then exit Excel, but it needs to be modified
to not save the file if the users clicks on the cancel button in the SaveAs
dialog box. I am a novice when it comes to this so any assistance with
specific examples will be greatly appreciated.

Sub saveexit()
'
' saveexit1 Macro
' Macro recorded 03/31/2008 by Barry Lerman
'
'
With ActiveWindow
strDate = Range("d2")
strDate1 = Format(Range("L2"), "mm-dd-yy")
Application.Dialogs(xlDialogSaveAs).Show _
arg1:=ActiveWorkbook.Path & "\" & strDate & " - " & "PPE" & " " & strDate1 &
" " & "T&A Worksheet", arg2:=1
ActiveWorkbook.RunAutoMacros Which:=xlAutoClose
Application.Quit
ThisWorkbook.Close SaveChanges:=True

End With
End Sub

Malik[_2_]

SaveAs
 
Hi,

Try this:
' Please change this line
If
Application.Dialogs(xlDialogSaveAs).Show(arg1:=Act iveWorkbook.Path & _
"\" & strDate & " - " & "PPE" & " " & strDate1 & " " & "T&A
Worksheet", arg2:=1) = True Then
ActiveWorkbook.RunAutoMacros Which:=xlAutoClose
Application.Quit
ThisWorkbook.Close SaveChanges:=True
End If

*** Cancel button will return FALSE ***
--
Malik


"blerman" wrote:

I have created the following macro, which is supposed to save the file based
on values in specific cells and then exit Excel, but it needs to be modified
to not save the file if the users clicks on the cancel button in the SaveAs
dialog box. I am a novice when it comes to this so any assistance with
specific examples will be greatly appreciated.

Sub saveexit()
'
' saveexit1 Macro
' Macro recorded 03/31/2008 by Barry Lerman
'
'
With ActiveWindow
strDate = Range("d2")
strDate1 = Format(Range("L2"), "mm-dd-yy")
Application.Dialogs(xlDialogSaveAs).Show _
arg1:=ActiveWorkbook.Path & "\" & strDate & " - " & "PPE" & " " & strDate1 &
" " & "T&A Worksheet", arg2:=1
ActiveWorkbook.RunAutoMacros Which:=xlAutoClose
Application.Quit
ThisWorkbook.Close SaveChanges:=True

End With
End Sub


blerman

SaveAs
 
When it copied this code I receive a compile syntax error. Any suggestions?

"blerman" wrote:

I have created the following macro, which is supposed to save the file based
on values in specific cells and then exit Excel, but it needs to be modified
to not save the file if the users clicks on the cancel button in the SaveAs
dialog box. I am a novice when it comes to this so any assistance with
specific examples will be greatly appreciated.

Sub saveexit()
'
' saveexit1 Macro
' Macro recorded 03/31/2008 by Barry Lerman
'
'
With ActiveWindow
strDate = Range("d2")
strDate1 = Format(Range("L2"), "mm-dd-yy")
Application.Dialogs(xlDialogSaveAs).Show _
arg1:=ActiveWorkbook.Path & "\" & strDate & " - " & "PPE" & " " & strDate1 &
" " & "T&A Worksheet", arg2:=1
ActiveWorkbook.RunAutoMacros Which:=xlAutoClose
Application.Quit
ThisWorkbook.Close SaveChanges:=True

End With
End Sub



All times are GMT +1. The time now is 07:04 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com