excel_learner
05-04-2011, 03:39 PM
I have following codes which prints the selected sheet within range in the workbook. Now, I want to be able to without deleting or disturbing the range, select the sheets which i want to print by marking them "x" in the next column. And other thing which i want to do is to be able to print some sheets from other workbook (as the workbook should be opened and selected sheet printed) but in same directory, if i specify the print range in the existing range of sheets which are to be printed.
Kindly advise.
Option Explicit
Sub Print_Ranges()
Dim strShtname As String, strRngName As String
Dim i As Long
With Worksheets("INDEX")
'sort the named range list according to page number order
.Range("A2").CurrentRegion.Sort key1:=Range("A3"), order1:=xlAscending, Header:=xlYes, ordercustom:=1, Orientation:=xlTopToBottom
'loop through the cells and determine parent of named range and specific range addresses
For i = 3 To 34
strRngName = .Cells(i, 2).Text
strShtname = Range(strRngName).Parent.Name
'clear any existing print areas and reset to named ranges areas
With Worksheets(strShtname)
.PageSetup.PrintArea = ""
.PageSetup.PrintArea = Range(strRngName).Address
.PrintOut
' .PrintPreview
End With
Next i
End With
End Sub
Kindly advise.
Option Explicit
Sub Print_Ranges()
Dim strShtname As String, strRngName As String
Dim i As Long
With Worksheets("INDEX")
'sort the named range list according to page number order
.Range("A2").CurrentRegion.Sort key1:=Range("A3"), order1:=xlAscending, Header:=xlYes, ordercustom:=1, Orientation:=xlTopToBottom
'loop through the cells and determine parent of named range and specific range addresses
For i = 3 To 34
strRngName = .Cells(i, 2).Text
strShtname = Range(strRngName).Parent.Name
'clear any existing print areas and reset to named ranges areas
With Worksheets(strShtname)
.PageSetup.PrintArea = ""
.PageSetup.PrintArea = Range(strRngName).Address
.PrintOut
' .PrintPreview
End With
Next i
End With
End Sub