G
Graham
I have a multisheet workbook where I want to go through each of the
worksheets and print out a fixed range in each worksheet if cell C2 is > 0.
I have highlighted areas which will be "unhighlighted" for printing and then
returned to their original state after printing. (thanks to help from Dave
Peterson). These latter highlighted areas are named with the worksheet name
that they reside in. My attempt is shown below.
Sub printmargins()
Dim myRng As Range
Dim myColorIndex As Long
Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
If Range("C2") > 0 Then
Set myRng = ActiveSheet.Range("Highlight")
myColorIndex = myRng(1).Interior.ColorIndex
myRng.Interior.ColorIndex = xlNone
sh.Range("a1:d20").PrintOut
myRng.Interior.ColorIndex = myColorIndex
End If
Next
End Sub
My problem is that with each sheet (these are not named Sheet1 Sheet2 etc),
the highlighted area name will change with the name of the sheet. ie set
myRng=ActiveSheet.Range("Sheetname") etc and quite simply I do not know how
to show this, and after that even if this will then work. Grateful for any
guidance or criticism.
Kind Regards,
Graham Haughs
Turriff, Scotland
worksheets and print out a fixed range in each worksheet if cell C2 is > 0.
I have highlighted areas which will be "unhighlighted" for printing and then
returned to their original state after printing. (thanks to help from Dave
Peterson). These latter highlighted areas are named with the worksheet name
that they reside in. My attempt is shown below.
Sub printmargins()
Dim myRng As Range
Dim myColorIndex As Long
Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
If Range("C2") > 0 Then
Set myRng = ActiveSheet.Range("Highlight")
myColorIndex = myRng(1).Interior.ColorIndex
myRng.Interior.ColorIndex = xlNone
sh.Range("a1:d20").PrintOut
myRng.Interior.ColorIndex = myColorIndex
End If
Next
End Sub
My problem is that with each sheet (these are not named Sheet1 Sheet2 etc),
the highlighted area name will change with the name of the sheet. ie set
myRng=ActiveSheet.Range("Sheetname") etc and quite simply I do not know how
to show this, and after that even if this will then work. Grateful for any
guidance or criticism.
Kind Regards,
Graham Haughs
Turriff, Scotland