Print size change using VBA.

imback2nite

Board Regular
Joined
Oct 30, 2004
Messages
211
Office Version
  1. 2003 or older
Platform
  1. Windows
I'm hoping this is a stupid question. I use the code below to print a page. The problem is when I print to pdf, it comes out fine. Even when I print the pdf file. When I print to paper the print range I set is not used. The page prints twice the size in width. What am I doing wrong? Thank you in advance.

Rich (BB code):
Private Sub CommandButton4_Click()
    Application.ScreenUpdating = False
   YesNo = MsgBox("This Action Will Print, 'Tally Sheet'      " & vbCr _
    & "                   Continue?", vbYesNo + vbInformation, "Caution")
    Select Case YesNo
    Case vbYes
    With ActiveSheet.PageSetup
        .PrintTitleRows = "$1:$19"
        .PrintTitleColumns = ""
    End With
    ActiveSheet.PageSetup.PrintArea = "$B$1:$N$319"
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = "&""Tahoma,Bold""CONFIDENTIAL"
        .RightHeader = ""
        .CenterFooter = "Page &P of &N"
        .RightFooter = ""
        .LeftMargin = Application.InchesToPoints(0#)
        .RightMargin = Application.InchesToPoints(0#)
        .TopMargin = Application.InchesToPoints(0.5)
        .BottomMargin = Application.InchesToPoints(0.5)
        .HeaderMargin = Application.InchesToPoints(0.25)
        .FooterMargin = Application.InchesToPoints(0.25)
        .CenterHorizontally = True
        .Orientation = xlPortrait
        .Zoom = 52
        .Draft = False
    End With
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
    Range("B1").Select
     Application.ScreenUpdating = True
Case vbNo
    Application.ScreenUpdating = False
    Range("B1").Select
    Application.ScreenUpdating = True
    End Select
End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Try this (small edit to your code).
VBA Code:
Private Sub CommandButton4_Click()
    Application.ScreenUpdating = False
   YesNo = MsgBox("This Action Will Print, 'Tally Sheet'      " & vbCr _
    & "                   Continue?", vbYesNo + vbInformation, "Caution")
    Select Case YesNo
    Case vbYes
    With ActiveSheet.PageSetup
        .PrintTitleRows = "$1:$19"
        .PrintTitleColumns = ""
    End With
    ActiveSheet.PageSetup.PrintArea = "$B$1:$N$319"
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = "&""Tahoma,Bold""CONFIDENTIAL"
        .RightHeader = ""
        .CenterFooter = "Page &P of &N"
        .RightFooter = ""
        .LeftMargin = Application.InchesToPoints(0#)
        .RightMargin = Application.InchesToPoints(0#)
        .TopMargin = Application.InchesToPoints(0.5)
        .BottomMargin = Application.InchesToPoints(0.5)
        .HeaderMargin = Application.InchesToPoints(0.25)
        .FooterMargin = Application.InchesToPoints(0.25)
        .CenterHorizontally = True
        .Orientation = xlPortrait
        .Zoom = 52
        .Draft = False
    End With
    ActiveSheet.PrintOut Copies:=1, Collate:=True
    Range("B1").Select
     Application.ScreenUpdating = True
Case vbNo
    Application.ScreenUpdating = False
    Range("B1").Select
    Application.ScreenUpdating = True
    End Select
End Sub
 
Upvote 0
This is what is happening. The first image is what it looks like printing to the printer. The second image is printing to PDF. The third is printing to PDF and THEN printing to the printer. I tried the change but still not working. 🤷‍♂️
 

Attachments

  • Printer Print.jpg
    Printer Print.jpg
    19.9 KB · Views: 6
  • PDF Print.jpg
    PDF Print.jpg
    20.2 KB · Views: 6
  • Print PDF on Printer.jpg
    Print PDF on Printer.jpg
    17 KB · Views: 6
Upvote 0
If this doesn't work the only thing that I can think of is setting Preview to True so that you can make the necessary changes before printing.
VBA Code:
Private Sub CommandButton4_Click()
    Application.ScreenUpdating = False
   YesNo = MsgBox("This Action Will Print, 'Tally Sheet'      " & vbCr _
    & "                   Continue?", vbYesNo + vbInformation, "Caution")
    Select Case YesNo
    Case vbYes
    With ActiveSheet.PageSetup
        .PrintTitleRows = "$1:$19"
        .PrintTitleColumns = ""
    End With
    ActiveSheet.PageSetup.PrintArea = "$B$1:$N$319"
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = "&""Tahoma,Bold""CONFIDENTIAL"
        .RightHeader = ""
        .CenterFooter = "Page &P of &N"
        .RightFooter = ""
        .LeftMargin = Application.InchesToPoints(0#)
        .RightMargin = Application.InchesToPoints(0#)
        .TopMargin = Application.InchesToPoints(0.5)
        .BottomMargin = Application.InchesToPoints(0.5)
        .HeaderMargin = Application.InchesToPoints(0.25)
        .FooterMargin = Application.InchesToPoints(0.25)
        .CenterHorizontally = True
        .Orientation = xlPortrait
        .Zoom = 52
        .Draft = False
    End With
    ActiveSheet.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:= True
    Range("B1").Select
     Application.ScreenUpdating = True
Case vbNo
    Application.ScreenUpdating = False
    Range("B1").Select
    Application.ScreenUpdating = True
    End Select
End Sub
 
Upvote 0
No. Still no dice. I had to resort to
.Zoom = 51
The print was already small. What's so odd is I'm using the same print code. What's the difference between paper and PDF?
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,128
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