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

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
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,214,649
Messages
6,120,730
Members
448,987
Latest member
marion_davis

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