Trying to save Excel unhide worksheets as pdf VBA code

Jasperlee93

New Member
Joined
Dec 6, 2022
Messages
7
Office Version
  1. 365
Platform
  1. Windows
anyone helps me please?
When I am working, I am using vba for saving excel each worksheets as pdf.
Sometimes, I don't need specific worksheets to be saved as PDF.

Please help ( :
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
anyone helps me please?
When I am working, I am using vba for saving excel each worksheets as pdf.
Sometimes, I don't need specific worksheets to be saved as PDF.

Please help ( :

Can you please share the code here.
 
Upvote 0
Sub ExportPDF()

Dim FDialog As FileDialog
Dim FPath As String
Dim Sht As Worksheet

Application.ScreenUpdating = False
Application.DisplayAlerts = False

Set FDialog = Application.FileDialog(msoFileDialogFolderPicker)
FDialog.InitialFileName = ThisWorkbook.Path

If FDialog.Show = -1 Then
FPath = FDialog.SelectedItems(1)
End If

If FPath <> "" Then

For Each Sht In ThisWorkbook.Sheets
Sht.ExportAsFixedFormat Type:=xlTypePDF, Filename:=FPath _
& Application.PathSeparator & Sht.Name & ".pdf"
Next Sht

End If

Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub


above vba code is what I am currently using.
 
Upvote 0
Can you please share the code here.
Sub ExportPDF()

Dim FDialog As FileDialog
Dim FPath As String
Dim Sht As Worksheet

Application.ScreenUpdating = False
Application.DisplayAlerts = False

Set FDialog = Application.FileDialog(msoFileDialogFolderPicker)
FDialog.InitialFileName = ThisWorkbook.Path

If FDialog.Show = -1 Then
FPath = FDialog.SelectedItems(1)
End If

If FPath <> "" Then

For Each Sht In ThisWorkbook.Sheets
Sht.ExportAsFixedFormat Type:=xlTypePDF, Filename:=FPath _
& Application.PathSeparator & Sht.Name & ".pdf"
Next Sht

End If

Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub


above vba code is what I am currently using.
 
Upvote 0
Sub ExportPDF()

Dim FDialog As FileDialog
Dim FPath As String
Dim Sht As Worksheet

Application.ScreenUpdating = False
Application.DisplayAlerts = False

Set FDialog = Application.FileDialog(msoFileDialogFolderPicker)
FDialog.InitialFileName = ThisWorkbook.Path

If FDialog.Show = -1 Then
FPath = FDialog.SelectedItems(1)
End If

If FPath <> "" Then

For Each Sht In ThisWorkbook.Sheets
Sht.ExportAsFixedFormat Type:=xlTypePDF, Filename:=FPath _
& Application.PathSeparator & Sht.Name & ".pdf"
Next Sht

End If

Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub


above vba code is what I am currently using.

The macro is extracting each sheet regardless if data is present or not . Is your sheet name and number of sheets are fixed ?
What is the first cell address for each sheet based on which you willl save it into pdf.
 
Upvote 0
The macro is extracting each sheet regardless if data is present or not . Is your sheet name and number of sheets are fixed ?
What is the first cell address for each sheet based on which you willl save it into pdf.
Thanks you for replying.

Is your sheet name and number of sheets are fixed ?
Nope, each sheet name can change and the number as well

What is the first cell address for each sheet based on which you willl save it into pdf.
The first cell address is A1

thanks!
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,312
Members
452,634
Latest member
cpostell

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