This should enable you to check if almost any object, including a single
area of cells, is within the printarea
Sub test()
res = IsInPrintArea(Selection)
MsgBox "IsInPrintArea = " & res
End Sub
Function IsInPrintArea(ByVal obj As Object) As Boolean
Dim bFlag As Boolean
Dim sAddr As String
Dim rngPrint As Range
Dim oWS As Object
'On Error GoTo errExit
If TypeName(obj.Parent) <> "Worksheet" Then
Set obj = obj.Parent ' Chart to ChartObject
If TypeName(obj.Parent) <> "Worksheet" Then
Set obj = obj.Parent ' Chart to ChartObject
End If
End If
Set ws = obj.Parent
sAddr = ws.PageSetup.PrintArea
If Len(sAddr) = 0 Then
' no custom printarea, so everything will be printed
IsInPrintArea = True
Else
Set rngPrint = ws.Range(sAddr)
For Each ar In rngPrint.Areas
With obj
If TypeName(obj) = "Range" Then
bFlag = _
Not Intersect(rngPrint, .Item(1)) Is Nothing _
And Not Intersect(rngPrint, .Item(.Count)) Is Nothing
Else
bFlag = _
Not Intersect(rngPrint, .TopLeftCell) Is Nothing _
And Not Intersect(rngPrint, .BottomRightCell) Is Nothing
End If
If bFlag Then Exit For
End With
Next
IsInPrintArea = bFlag
End If
errExit:
End Function
Regards,
Peter T