Hi all -
I am working on building a better report manager using named ranges
1.) Loop through the workbook and find all named ranges
Output the named ranges to a worksheet
2.) Read the values from the worksheet and print each one
Seem simple enough and is really just first step
Would also like to store all print settings next to each named range to be modified by user as needed and used to format report before printing each range as needed
But I'm getting ahead of myself.
First is to print a named range
My code is below
Error msg:
QuoteRun Time Error 91
Object variable or With Block Variable Not Set
Debug points here:
Though I'm not really sure as to why
Thanks much
-marc
Full code:
1. Loop through all named ranges and output to worksheet. This part works fine:
Option Explicit
Sub GetNamedRange()
Dim nName As Name
Dim wb As Workbook
Dim wsPrnt As Worksheet
Dim Row As Long
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.Calculation = xlCalculationManual
End With
Set wb = ThisWorkbook
Set wsPrnt = wb.Worksheets("prnt")
Row = 3
With wb
For Each nName In .Names
wsPrnt.Range("B" & Row) = nName.Name
Row = Row + 1
Next
End With
With Application
.ScreenUpdating = True
.DisplayAlerts = True
.Calculation = xlCalculationAutomatic
End With
Set nName = Nothing
Set wb = Nothing
Set wsPrnt = Nothing
End Sub
Display More
Snippet below is where I am trying to print the named range
Option Explicit
Sub PrintNamedRange()
Dim wb As Workbook
Dim wsPrnt As Worksheet
Dim lngRows As Long
Dim rngPrint As Range
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.Calculation = xlCalculationManual
End With
Set wb = ThisWorkbook
Set wsPrnt = wb.Worksheets("prnt")
lngRows = wsPrnt.Range("B65536").End(xlUp).Row
Set rngPrint.Name = wsPrnt.Range("B" & lngRows).Value
rngPrint.PrintOut
With Application
.ScreenUpdating = True
.DisplayAlerts = True
.Calculation = xlCalculationAutomatic
End With
Set wb = Nothing
Set wsPrnt = Nothing
Set rngPrint = Nothing
End Sub
Display More