letswriteafairytale
New Member
- Joined
- Dec 23, 2024
- Messages
- 13
- Office Version
- 365
- Platform
- Windows
I have created a userform with 3 buttons, "Save as .XLSM", "Save as .PDF" and "Cancel"
What I would like is for this command box to pop up when we go to save the document (click on save as > browse)
The buttons work just fine every time someone hits Save as .PDF.
BUT, it will only work once if someone chooses save as .XLSM, it will save as .xlsm, then when you go to save again, the save as dialog box opens, but doesn't actually ever save again.
Here is the BeforeSave VBA:
Here is the UserForm1 code:
What I would like is for this command box to pop up when we go to save the document (click on save as > browse)
The buttons work just fine every time someone hits Save as .PDF.
BUT, it will only work once if someone chooses save as .XLSM, it will save as .xlsm, then when you go to save again, the save as dialog box opens, but doesn't actually ever save again.
Here is the BeforeSave VBA:
VBA Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel as Boolean)
Cancel = True
UserForm1.Show
End Sub
Here is the UserForm1 code:
VBA Code:
Private Sub CommandButton1_Click()
Call Save_as_XLSM
End Sub
Private Sub CommandButton2_Click()
Call Save_as_PDF
End Sub
Private Sub CommandButton3_Click()
Call Cancel
End Sub
Private Sub Label1_Click()
End Sub
Private Sub Save_as_XLSM()
Dim ws As Sheet1
Dim filename As String
Dim saveAsDialog
Dim savePath As Variant
Set ws = ThisWorkbook.ActiveSheet
saveAsDialog = Application.GetSaveAsFilename( _
filefilter:="Macro-Enabled Workbook (*.xlsm), *xlsm", InitialFileName:="", Title:="Please choose location to save this document")
If saveAsDialog <> False Then
ActiveWorkbook.SaveAs filename:=saveAsDialog, FileFormat:=52
Exit Sub
End If
Unload Me
End Sub
Private Sub Save_as_PDF()
Dim ws As Sheet1
Dim filename As String
Dim saveAsDialog
Dim savePath As Variant
Set ws = ThisWorkbook.ActiveSheet
saveAsDialog = Application.GetSaveAsFilename( _
filefilter:="PDF Files (*.pdf), *pdf", InitialFileName:="", Title:="Please choose location to save this document")
If saveAsDialog <> False Then
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, filename:=saveAsDialog, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
Exit Sub
End If
Unload Me
End Sub
Private Sub Cancel()
Unload Me
End
End Sub
Private Sub Label2_Click()
End Sub
Private Sub UserForm_Click()
End Sub