Like to create a pdf file to save PDF

Polino

New Member
Joined
Apr 1, 2022
Messages
12
Office Version
  1. 2019
Platform
  1. Windows
I know it's sinple, but I'm very new at VBA
I like to create a PDF file from an excel worksheet:
Export sheet1 range D1:H10 and save with the name of F1 and G1 in sheet2
Ask for the directory location where to save and wait for the input name or change location
Sheet2 F1 has the name of the file Sheet2 G1 has the number of the file that will increase each time by 1 when the file is saved
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Try this:

Excel Formula:
Sub createpdf()
  Dim sPath As String, sName As String
  Dim number As Long
    
  With Application.FileDialog(msoFileDialogFolderPicker)
    .Title = "Select Folder"
    .AllowMultiSelect = False
    If .Show <> -1 Then Exit Sub
    sPath = .SelectedItems(1)
  End With
  
  sName = Sheets("Sheet2").Range("F1").Value
  number = Val(Sheets("Sheet2").Range("G1").Value)
    
  Sheets("Sheet1").Range("D1:H10").ExportAsFixedFormat Type:=xlTypePDF, _
    Filename:=sPath & "\" & sName & number & ".pdf", Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,551
Messages
6,114,266
Members
448,558
Latest member
aivin

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