vba pdf export custom size

Urraco

Board Regular
Joined
Apr 19, 2021
Messages
69
Office Version
  1. 2016
Platform
  1. Windows
Hi,
it is possible to export a row to pdf dimension size equal to:?
pdfWidth = A2
pdfHeight= B2
C2:G2 = content
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
try this... cheers!
VBA Code:
Sub print_dynamic_range_()
   Dim sRange As String, eRange As String
'''cell c2 is beginning range
   sRange = ActiveSheet.Range("c2"):
'''cell d2 is ending range
   eRange = ActiveSheet.Range("d2")
   Range(sRange & ":" & eRange).Select
    Application.PrintCommunication = False
    With ActiveSheet.PageSetup
        .PrintTitleRows = ""
        .PrintTitleColumns = ""
    End With
    ActiveSheet.PageSetup.PrintArea = ""
    Application.PrintCommunication = False
    With ActiveSheet.PageSetup
'''cells a2 and b2 are margin sizes
        .LeftMargin = Application.InchesToPoints(Range("b2"))
        .RightMargin = Application.InchesToPoints(Range("b2"))
        .TopMargin = Application.InchesToPoints(Range("a2"))
        .BottomMargin = Application.InchesToPoints(Range("a2"))
    End With
    Application.PrintCommunication = True
    Selection.PrintOut Copies:=1, Collate:=True
End Sub
 

Attachments

  • print_dynamic_range_.PNG
    print_dynamic_range_.PNG
    20.9 KB · Views: 6
Upvote 0

Forum statistics

Threads
1,221,700
Messages
6,161,378
Members
451,700
Latest member
Eccymarge

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