VBA Userform To List All Sheets, Selct Which To Convert to PDF and save on desktop

Jingles3X

New Member
Joined
Oct 20, 2021
Messages
34
Office Version
  1. 2013
Platform
  1. Windows
I am wondering if anyone has a code example ( yes, I used search but did not find what i am looking for).
I have created a spreadsheet, that has many worksheets. Each worksheet takes up 4 pages on the sheet.
I would like to create a userform that will list all sheets except the first three, then have checkboxes to
allow the user to select which pages to include in a single PDF file to be saved on the desktop.

I have been able to put together code that allows me to save everything to a single pdf, but I am not having
any luck with being able to select which sheets to print. Within that, I am only wanting to print the Top Left page
on each sheet, and the one below it. The other two have pricing information that should not be printed.

Here is the code I have used to print all pages of all sheets to pdf....im just looking to be able to select which in
a userform with checkboxes. Any help with how to modify for my needs will be appreciated.

VBA Code:
[B]Public Sub Save_Sheets_As_PDF()

Dim PDFfile As String
Dim currentSheet As Worksheet
Dim i As Long
Dim replaceSelected As Boolean
PDFfile = CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\" & "S2 Services Retail Pricing" & Format(Now, " DD-MMM-YY") & ".pdf"
With ActiveWorkbook
Set currentSheet = .ActiveSheet
replaceSelected = True
MsgBox .Sheets("Labor Calculator").Index + 2 & " " & .Sheets.Count
For i = .Sheets("Labor Calculator").Index + 2 To .Sheets.Count
.Sheets(i).Select replaceSelected
replaceSelected = False
Next
.ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDFfile, _
Quality:=xlQualityMinimum, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
currentSheet.Select True
MsgBox "Created " & PDFfile
End With

End Sub
[/B]
 

Excel Facts

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

Forum statistics

Threads
1,214,917
Messages
6,122,233
Members
449,075
Latest member
staticfluids

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