What is the print area called and how to call it in VBA?

DarkJester89

Board Regular
Joined
Nov 5, 2017
Messages
109
Office Version
  1. 2016
Platform
  1. Windows
1601736152125.png

I found this on search engine images but the print preview is what I have currently and it's not preferred for the user base because we can't adjust the printers or areas.

The code would for Sheet3, not active sheet but any advice is appreciated.

VBA Code:
Sub PrintPreview()
Sheet3.PrintOut preview:=True

End Sub

Thanks in advance
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Excel names the print area "Print_Area", a named range scoped to the worksheet level. In VBA you can treat it as a range like this:
Dim Rng as Range
Set Rng = Sheets("Sheet3").Range("Print_Area")

Note that you must include the worksheet since the named range is scoped to it.
 
Upvote 0
VBA Code:
Sub PrintArea()
    Dim Rng As Range
    Set Rng = Sheets("Sheet3").Range("Print_Area")
End Sub

Run Time Error 1004 Applicated Defined or Object defined area with actual sheet name

Run time error 9, subscript out of range with Sheet3 name
 
Upvote 0
The 1st error normally means you haven't defined a print area so it is going by it's default setup.
The 2nd error normally means you haven't got a sheet named Sheet3.
 
Upvote 0
Think I would just to need to find a vba to set the print area, Column B to H (that's the usual area intended).

VBA Code:
Worksheets("Sheet3").PageSetup.PrintArea = "B:H"
 
Upvote 0
And the row number or just the last row?
If just the columns try (untested)
VBA Code:
Worksheets("Sheet3").PageSetup.PrintArea = Range("B:H").Address
 
Upvote 0
So that part works but now it won't call the Sheet3 to print, i have it coded, the command button clicks but doesn't do anything, doesn't debug or anything
 
Upvote 0
VBA Code:
Private Sub CommandButton1_Click()
    Call SetArea
    Call PrintArea
End Sub

Code:
Sub SetArea()
    Worksheets("Sheet3").PageSetup.PrintArea = Range("D:L").Address
End Sub

Sub PrintArea()
    Dim Rng As Range
    Set Rng = Sheets("Sheet3").Range("Print_Area")
End Sub
 
Upvote 0
You're not telling it to PrintOut in either of those codes.
You need the line
VBA Code:
WorkSheets("Sheet3").PrintOut
or
VBA Code:
WorkSheets("Sheet3").PrintPreview
You also don't need the 2nd code if you are using the first, just
VBA Code:
Sub SetArea()
     Worksheets("Sheet3").PageSetup.PrintArea = Range("D:L").Address
     WorkSheets("Sheet3").PrintOut
End Sub
 
Upvote 0
@MARK858 This works but is there a way I can get to the Print Prep screen for printer/setting designation. Activating this sends its straight to printer with no option selection.

Print Preview doesn't give the option to pick the printer/save to PDF. so the feature like this. Thank you in advance!
printer.png
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,332
Members
449,077
Latest member
jmsotelo

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