unable to set print range with named range's address -- need a second pair of eyes

OaklandJim

Well-known Member
Joined
Nov 29, 2018
Messages
833
Office Version
  1. 365
Platform
  1. Windows
Team Messieurs Excel

I know there is something simple that I'm missing so please have a quick look. Sub is merely trying to set the print area (and row and column headers) for printing. It hangs on my attempt to set the Print_Area range (PrintRange property) to the address of a named range. The NAME of the range (whose address) is used to set the worksheet Print_Area is specified by param psPrintArea. Here is what I have.

VBA Code:
Private Sub PortfolioPrintAreaSetup( _
    psPrintArea, _
    psRowRange, _
    psColRange, _
    Optional pwsSheet As Worksheet)

    If IsMissing(pwsSheet) _
     Then
        pwsSheet = ActiveSheet
    End If

    Application.PrintCommunication = False

Debug.Print pwsSheet.Range(psPrintArea).Address
'Result: $A$3:$BK$112 -- the correct address

Debug.Print pwsSheet.Name
'Result: Portfolio -- the correct worksheet name

    With pwsSheet.PageSetup
        .PrintArea = .Range(psPrintArea).Address
        .PrintTitleRows = .Range(psRowRange).Address
        .PrintTitleColumns = .Range(psColRange).Address
    End With

    Application.PrintCommunication = True

End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Haven't looked carefully at your code, and haven't tested this, but I'd try replacing the with-end with block just before Application.PrintCommunication = True with this:
VBA Code:
With pwsSheet
    With .PageSetup
            .PrintArea = .Range(psPrintArea).Address
            .PrintTitleRows = .Range(psRowRange).Address
            .PrintTitleColumns = .Range(psColRange).Address
    End With
End With
 
Upvote 0
Thanx Joe but Nope. That is where I started. Retried it just now. It must be something obvious that I'm not seeing.
 
Upvote 0
Thanx Joe but Nope. That is where I started. Retried it just now. It must be something obvious that I'm not seeing.
If the Print_Area is a named range, does this work?
With .pageSetup
.PrintArea = .Range("Name of named range").address
......
 
Upvote 0
I appreciate the effort Joe, really. Thank you.

That is what I am trying to do. I'm missing something obvious. And, I know that I've done it in the past.

I went in a tangential direction. I fiddled a bit with the "built-in" named ranges for printing and wuz able to set RefersTo for THOSE. A half-bassackwards approach that seems to work.

VBA Code:
    With pwsSheet

        sRefersTo = "=" & .Range("Print_Area_All").Address

        .Names("Print_Area").RefersTo = sRefersTo
    
        sRefersTo = "=" & .Range(psColRange).Address _
        & "," & .Range(psRowRange).Address
        
        .Names("Print_Titles").RefersTo = sRefersTo
    
    End With
 
Upvote 0
Solution
Glad you got it sorted - thanks for the reply.
 
Upvote 0

Forum statistics

Threads
1,215,056
Messages
6,122,907
Members
449,096
Latest member
dbomb1414

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