View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Chart on a worksheet, find chart location

Ps. I did assume that the print range was a single area, too! That's not
always true.

Dave Peterson wrote:

The print range (if it's been set) has a topleftcell and a bottomrightcell.

The chart also has a topleftcell and a bottomrightcell.

The chart could be entirely outside the print range, overlap slightly or be
entirely within the print range.

I'm not sure what distinction you're looking for, but this may give you a few
ideas:

Option Explicit
Sub testme()
Dim wks As Worksheet
Dim ChtObject As ChartObject
Dim myPrintRng As Range
Dim myChartRng As Range

'I used sheet1
Set wks = Worksheets("Sheet1")

With wks
Set myPrintRng = Nothing
On Error Resume Next
Set myPrintRng = .Range(.PageSetup.PrintArea)
On Error GoTo 0

If myPrintRng Is Nothing Then
MsgBox "The print range hasn't been set!"
Exit Sub
End If

'What's the name of the chart?
Set ChtObject = .ChartObjects("Chart 1")

With ChtObject
Set myChartRng = .Parent.Range(.TopLeftCell, .BottomRightCell)
End With

If Intersect(myPrintRng, myChartRng) Is Nothing Then
MsgBox "Separate with no overlap"
ElseIf Union(myPrintRng, myChartRng).Address = myPrintRng.Address Then
MsgBox "Contained in the print range"
Else
MsgBox "a little overlap"
End If
End With

End Sub

headly wrote:

What kind of VBA command(s) are there to determine if a chart (located on a
worksheet) is inside the print range/area? TIA for suggestions/advice


--

Dave Peterson


--

Dave Peterson