Re: Print Named Ranges
Hi PCI,
Many thanks for your help.
It is a generic vba solution that I am trying to create so that I can port a homemade printing manager to many different workbooks. I find the downloadable Report Manager very lacking.
At any rate, I downloaded the file and took a look
Appears to only get the names of named ranges in the workbook and list them.
My code already does that (many more lines than yours). But it works.
Now what I would like to do in the next procedure is read the name of the range that was listed
And then print that range. In the end, I will loop through all of the named ranges and print each one.
Thanks again for your help.
marc[hr]*[/hr] Auto Merged Post;[dl]*[/dl]Hi all -
I've done quite a bit of searching on the internet and tried many things - all of which fail.
The code below works up to
Which returns the string tblWeightDist as expected (tblWeightDist is a named range - name is stored in a cell in the workbook)
The code below error's at
Set rngPrint.Name = strName
So apparently Excel does not like me trying to assign a string variable to a range.name
I guess where I am struggling is
- how to now pass strName into a named range
- get the address of the named range
- printout the address
Full code below
Thanks much for the great help
Regards,
marc
Option Explicit
Sub PrintNamedRange()
Dim wb As Workbook
Dim wsPrnt As Worksheet
Dim lngRows As Long
Dim nName As Name
Dim strName As String
Dim rngPrint As Range
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.Calculation = xlCalculationManual
End With
'Initialize
Set wb = ThisWorkbook
Set wsPrnt = wb.Worksheets("prnt")
lngRows = wsPrnt.Range("B65536").End(xlUp).Row
strName = wsPrnt.Range("B" & lngRows).Value
'Test
Debug.Print strName
'Select Range & Print
Set rngPrint.Name = strName
rngPrint.Select
ActiveSheet.PageSetup.PrintArea = rngPrint.Address
ActiveSheet.PrintOut
'Cleanup
With Application
.ScreenUpdating = True
.DisplayAlerts = True
.Calculation = xlCalculationAutomatic
End With
Set wb = Nothing
Set wsPrnt = Nothing
Set rngPrint = Nothing
End Sub
Display More