Determine printable area width according to active printer

Hello,
How to determine printable area width according to active printer?
I can see value in Print Preview window when Fit to page is selected in fields for width/height but I need VBA code 
Greetings!

Parents
No Data
Reply
  • @ rainbow friends

    Hello, To determine the printable area width according to the active printer using VBA code, you can utilize the PageSetup object from the Excel library. Here's an example of how you can achieve this:

    vba
    Sub GetPrintableAreaWidth()
    Dim ws As Worksheet
    Dim ps As PageSetup
    Dim printableAreaWidth As Double

    ' Set the active worksheet
    Set ws = ActiveSheet

    ' Set the PageSetup object
    Set ps = ws.PageSetup

    ' Calculate the printable area width in inches
    printableAreaWidth = ps.PrintableWidth / Application.InchesToPoints(1)

    ' Display the printable area width
    MsgBox "Printable Area Width: " & printableAreaWidth & " inches"
    End Sub

Children