VBA - Print to PDF with file name from a cell

khalid007

New Member
Joined
Apr 7, 2018
Messages
2
Dear All

I am new to VBA. I have the below code which is a printing loop to a specific number specified in Cell A2.

Code:
[/COLOR]Sub PrintLeveCal()'
' PrintLeveCal Macro
'


'
    Emp = 1
    Do While Emp <= Sheets("Invoice").Range("A2").Value
    Sheets("Invoice").Select
    Range("A1").Value = Emp
    Range("A6:J75").Select
    ActiveSheet.PageSetup.PrintArea = "$A$6:$J$75"
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    Emp = Emp + 1
Loop
Sheets("Invoice").Select
Reply = MsgBox("All invoices has been printed", vbInformation + vbOKOnly)

End Sub[COLOR=#333333]

Now I want to modify the code to Print it as PDF, with file name from a Cell and to a specific location, suppose C:\Output.

Thanks in Advance.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
What cell will have the file name?

Each pdf file will need a different file name. Will that cell value change for each time in the print loop?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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