Save as XLSM & PDF VBA Code Help

letswriteafairytale

New Member
Joined
Dec 23, 2024
Messages
12
Office Version
  1. 365
Platform
  1. Windows
I have been working on creating some templates for office use on a network server for a while, and have played with MANY different ways to do what I would like to achieve.

I've come to the conclusions of using UserForms and custom buttons. I've found a code that kind of does what I need, but not exactly.

My 2 buttons are "Save as .xlsm" & "Save as .pdf"

What I would like for those 2 buttons to do are, open the save as dialog, but only have the chosen file type, and let the person pick a folder and name it themselves.

I found a few codes that I've tried adjusting and editing to get what I want, but I am just struggling. This is the one for the PDF that will work, IF I can get a code for the .xlsm to work first(we save as xlsm before it is reviewed & finalized as a PDF, so I don't NEED to re-name the PDF if the xlsm is correct)

VBA Code:
Private Sub Save_as_PDF()
   Dim Fldr As String
  
   With Application.FileDialog(4)
      .AllowMultiSelect = False
      If .Show Then Fldr = .SelectedItems(1)
   End With
   With ActiveSheet
      .ExportAsFixedFormat xlTypePDF, Fldr & "\" & .Name, , , 1, , , 0
   End With
End Sub


This is the XLSM sub that I need help with:

VBA Code:
Private Sub Save_as_XLSM()

End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Figured it out.

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 Worksheet
    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


End Sub

Private Sub Save_as_PDF()
   Dim ws As Worksheet
    Dim fileName As String
    Dim saveAsDialog
    Dim savePath As Variant

    Set ws = ThisWorkbook.ActiveSheet

saveAsDialog = Application.GetSaveAsFilename( _
    FileFilter:="pdf (*.PDF), *PDF", InitialFileName:="", Title:="Please choose location to save this document")

  If saveAsDialog <> False Then
       ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF
    End If
End Sub


Private Sub Cancel()
Unload Me
    End
End Sub

Private Sub UserForm_Click()

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,225,277
Messages
6,184,013
Members
453,205
Latest member
aromera

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top