Modifying Create Pdf Macro

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
Found this code here on the forum and need help with modification :

Code:
Private Sub CommandButton2_Click()
'This macro opens the SaveAs option with the defult file path "you have to set this file path below" coverts the whole sheet into .pdf file format
'And opens the .pdf to view <-- you can disable the view after covert option with lower code: OpenAfterPublish:=False

    pdfName = ActiveSheet.Range("T1")
    ChDir "C:\Temp\" 'This is where youo set a defult file path.
    fileSaveName = Application.GetSaveAsFilename(pdfName, _
    fileFilter:="PDF Files (*.pdf), *.pdf")
    If fileSaveName <> False Then
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, fileName:= _
        fileSaveName _
        , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
        :=False, OpenAfterPublish:=True
    End If
    MsgBox "File Saved to" & " " & fileSaveName
End Sub

I want it to save without asking me to choose the file name. Then the file path should be in a folder called MyPdf in the ThisWorkbook. Path
Thanks in advance
Kelly
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
I want it to save without asking me to choose the file name. Then the file path should be in a folder called MyPdf in the ThisWorkbook. Path
Is this what you mean?

Code:
Private Sub CommandButton2_Click()
  Dim pdfName As String, FileFullName As String
  
  pdfName = Range("T1").Value
  FileFullName = ThisWorkbook.Path & "\MyPdf\" & pdfName
  ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=FileFullName, Quality:=xlQualityStandard, _
                                  IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
  MsgBox "File Saved to" & " " & FileFullName
End Sub
 
Last edited:
Upvote 0
Yes exactly. Thanks . I have adjusted it to suit my need. One thing I like most about this is that it overrides the old file.
Kelly
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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