VBA code to create PDF for printing

MacroNobie

New Member
Joined
Mar 29, 2018
Messages
12
Hi everybody,

I am looking for a code, which creates a Pdf from the active sheet (specific range), so you can print that Pdf. Is there a way to do that without specifying a path where to save the file because it is only needed for printing?

Thanks for your help!

Best regards,
Nawid
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
why create a pdf?
- you can print a range from Excel
 
Upvote 0
My problem is I have hidden rows and it does not show these rows when I normally press on print but it also would be nice to create a print button. Can you help on that part?>
Thanks a lot!
 
Upvote 0
how about some VBA TO ...
- MAKE VISIBLE all "hidden" rows
- PRINT selected pages
- HIDE previously "hidden" rows

like this...
Code:
Sub PrintPages()
    Dim first As Integer, last As Integer
    Dim UsedRng As Range, HiddenRng As Range, cel As Range
    Set UsedRng = ActiveSheet.UsedRange.Resize(, 1)
    Set HiddenRng = ActiveSheet.Cells(Rows.Count, 1)
'determine hidden rows
    For Each cel In UsedRng
        If cel.EntireRow.Hidden Then Set HiddenRng = Union(HiddenRng, cel)
    Next
'make them visible
    HiddenRng.EntireRow.Hidden = False
'print required pages
    first = InputBox("First page?", "Print from...", 1)
    last = InputBox("Last page?", "Print up to...", 1)
    ActiveSheet.PrintOut From:=first, To:=last
'hide the rows again
    HiddenRng.EntireRow.Hidden = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
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