Excel to PDF Saving

austinandreikurt

Board Regular
Joined
Aug 25, 2020
Messages
91
Office Version
  1. 2016
Platform
  1. Windows
Hi,
I would like to ask for help in saving an excel sheets into PDF form. Note that there are currently 3 excel sheets to be converted to PDF and it is just one file but the number of excel sheets should be the number of PDF page to be save. It will start with Sheet2 and so on. It is only 3 Sheets now but I need it to be extended up to the last excel sheet because the user may add another one. The excel sheets are named in order that it is in VBA form so the actual arrangement of the sheets is not a problem as the code will based it on the Sheet number (e.g Sheet2 to Sheet4). The only case here is to know what is the last Sheet number. Second, I want the PDF filename that is based on Cell G5 of Sheet2 and the folder where it will be saved will be left for the user to browse then the saving will continue. Thanks in advance!
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Try this

VBA Code:
Sub SavePdf()
  Dim sName As String, spath As String
  Dim i As Long
  
  If Sheets.Count = 1 Then Exit Sub
  sName = Replace(Sheets(2).Range("G5").Value, "/", "-")
  If sName = "" Then
    MsgBox "Cell G5 is empty"
    Exit Sub
  End If
  For i = 2 To Sheets.Count
    Sheets(i).Select Replace:=i = 2
  Next
  
  With Application.FileDialog(msoFileDialogFolderPicker)
    .Title = "Select Folder"
    .AllowMultiSelect = False
    If .Show <> -1 Then Exit Sub
    spath = .SelectedItems(1)
  End With

  ActiveSheet.ExportAsFixedFormat xlTypePDF, spath & "\" & sName, xlQualityStandard, True, False, , , False
  Sheets(2).Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,792
Messages
6,121,612
Members
449,038
Latest member
apwr

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