Save to PDF

jlwag

New Member
Joined
Feb 18, 2020
Messages
4
Office Version
  1. 365
Platform
  1. Windows
I have the following macro that prints to the printer just find, but I would like to know how to send them to a PDF file instead.

Sub PrintAllMSEL()

RowCount = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row - 1

Worksheets("PrintMSEL").Select
For i = 1 To RowCount
Range("B1").Value = i
ActiveSheet.PrintOut copies:=1
Next i
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Code:
Worksheets("PrintMSEL").ExportAsFixedFormat xlTypePDF, ThisWorkbook.Path & "\" & "Name to be saved as here" & ".pdf"

Saves in the same folder where the excel workbook resides.
 
Upvote 0
In your Post #1, is Sheet1 the same as the Sheet you're printing ("PrintMSEL")?
 
Upvote 0
If Sheet1 and "PrintMSEL" are the same sheet and your print range has been set, this should be what you need.
If these assumptions are wrong, you'll have to explain in detail what is required.
Code:
Sub To_PDF()
Dim i As Long
Dim sh1 As Worksheet
Set sh1 = Worksheets("PrintMSEL")
    For i = 1 To sh1.Cells(Rows.Count, 1).End(xlUp).Row
        sh1.Cells(1, 2).Value = i
        Worksheets("PrintMSEL").ExportAsFixedFormat xlTypePDF, ThisWorkbook.Path & "\" & sh1.Name & "-" & sh1.Cells(1, 2).Value & ".pdf"
    Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,265
Members
452,627
Latest member
KitkatToby

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