PC Review


Reply
Thread Tools Rate Thread

Determining if ChartObject is in PrintArea on Worksheet

 
 
Barb Reinhardt
Guest
Posts: n/a
 
      10th Sep 2008
I'm trying to determine if a ChartObject is within the Print_Area on a given
worksheet and have this code. I've noted in the code where execution ends.
I've done a "debug.print" and see that the topleftcell is in the Print_area,
but I'm not sure why it's quitting on me. Does anyone have any ideas?


Dim ChtObj As Excel.ChartObject
Dim myRange As Range

myChartInRange = False


On Error Resume Next
Set myRange = myWS.Range("Print_Area")
On Error GoTo 0
If myRange Is Nothing Then Exit Sub

For Each ChtObj In myWS.ChartObjects
myChartInRange = False
'Execution in this sub ends on the line below
If Not Intersect(ChtObj.TopLeftCell, myRange) Is Nothing Then
Debug.Print "Top Left in Range", myWS.Name, ChtObj.Name
Set myChtObj = ChtObj
myChartInRange = True
Exit For
End If
Next ChtObj
Debug.Print
--
HTH,
Barb Reinhardt


 
Reply With Quote
 
 
 
 
Jon Peltier
Guest
Posts: n/a
 
      10th Sep 2008
Barb -

I ran this fine in 2003 (SP3) and 2007 (SP1). I don't think I changed
anything meaningful.

I used this sub to test the function in 2003 and 2007. In all cases I got
True or False in the debug window and the beep at the end of the function. I
don't know why you had problems, unless it's related to some fixes made in
SP1.

Sub test()
Debug.Print myChartInRange
End Sub

This is the function. I don't think I changed anything meaningful from what
you posted.

Function myChartInRange()
Dim myWS As Worksheet
Dim ChtObj As Excel.ChartObject
Dim myChtObj As Excel.ChartObject
Dim myRange As Range

myChartInRange = False
Set myWS = ActiveSheet

On Error Resume Next
Set myRange = myWS.Range("Print_Area")
On Error GoTo 0
If myRange Is Nothing Then Exit Function

For Each ChtObj In myWS.ChartObjects
myChartInRange = False
'Execution in this sub ends on the line below
If Not Intersect(ChtObj.TopLeftCell, myRange) Is Nothing Then

Debug.Print "Top Left in Range", myWS.Name, ChtObj.Name
Set myChtObj = ChtObj
myChartInRange = True
Exit For

End If
Next ChtObj
Beep
End Function


- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Barb Reinhardt" <(E-Mail Removed)> wrote in message
news:7281A7D4-9777-471F-AD93-(E-Mail Removed)...
> I'm trying to determine if a ChartObject is within the Print_Area on a
> given
> worksheet and have this code. I've noted in the code where execution
> ends.
> I've done a "debug.print" and see that the topleftcell is in the
> Print_area,
> but I'm not sure why it's quitting on me. Does anyone have any ideas?
>
>
> Dim ChtObj As Excel.ChartObject
> Dim myRange As Range
>
> myChartInRange = False
>
>
> On Error Resume Next
> Set myRange = myWS.Range("Print_Area")
> On Error GoTo 0
> If myRange Is Nothing Then Exit Sub
>
> For Each ChtObj In myWS.ChartObjects
> myChartInRange = False
> 'Execution in this sub ends on the line below
> If Not Intersect(ChtObj.TopLeftCell, myRange) Is Nothing Then
> Debug.Print "Top Left in Range", myWS.Name, ChtObj.Name
> Set myChtObj = ChtObj
> myChartInRange = True
> Exit For
> End If
> Next ChtObj
> Debug.Print
> --
> HTH,
> Barb Reinhardt
>
>



 
Reply With Quote
 
Barb Reinhardt
Guest
Posts: n/a
 
      10th Sep 2008
I'm testing it in 2003 right now and it gacks. I'll try your code and see if
it works.

Thanks,
Barb

"Jon Peltier" wrote:

> Barb -
>
> I ran this fine in 2003 (SP3) and 2007 (SP1). I don't think I changed
> anything meaningful.
>
> I used this sub to test the function in 2003 and 2007. In all cases I got
> True or False in the debug window and the beep at the end of the function. I
> don't know why you had problems, unless it's related to some fixes made in
> SP1.
>
> Sub test()
> Debug.Print myChartInRange
> End Sub
>
> This is the function. I don't think I changed anything meaningful from what
> you posted.
>
> Function myChartInRange()
> Dim myWS As Worksheet
> Dim ChtObj As Excel.ChartObject
> Dim myChtObj As Excel.ChartObject
> Dim myRange As Range
>
> myChartInRange = False
> Set myWS = ActiveSheet
>
> On Error Resume Next
> Set myRange = myWS.Range("Print_Area")
> On Error GoTo 0
> If myRange Is Nothing Then Exit Function
>
> For Each ChtObj In myWS.ChartObjects
> myChartInRange = False
> 'Execution in this sub ends on the line below
> If Not Intersect(ChtObj.TopLeftCell, myRange) Is Nothing Then
>
> Debug.Print "Top Left in Range", myWS.Name, ChtObj.Name
> Set myChtObj = ChtObj
> myChartInRange = True
> Exit For
>
> End If
> Next ChtObj
> Beep
> End Function
>
>
> - Jon
> -------
> Jon Peltier, Microsoft Excel MVP
> Tutorials and Custom Solutions
> Peltier Technical Services, Inc. - http://PeltierTech.com
> _______
>
>
> "Barb Reinhardt" <(E-Mail Removed)> wrote in message
> news:7281A7D4-9777-471F-AD93-(E-Mail Removed)...
> > I'm trying to determine if a ChartObject is within the Print_Area on a
> > given
> > worksheet and have this code. I've noted in the code where execution
> > ends.
> > I've done a "debug.print" and see that the topleftcell is in the
> > Print_area,
> > but I'm not sure why it's quitting on me. Does anyone have any ideas?
> >
> >
> > Dim ChtObj As Excel.ChartObject
> > Dim myRange As Range
> >
> > myChartInRange = False
> >
> >
> > On Error Resume Next
> > Set myRange = myWS.Range("Print_Area")
> > On Error GoTo 0
> > If myRange Is Nothing Then Exit Sub
> >
> > For Each ChtObj In myWS.ChartObjects
> > myChartInRange = False
> > 'Execution in this sub ends on the line below
> > If Not Intersect(ChtObj.TopLeftCell, myRange) Is Nothing Then
> > Debug.Print "Top Left in Range", myWS.Name, ChtObj.Name
> > Set myChtObj = ChtObj
> > myChartInRange = True
> > Exit For
> > End If
> > Next ChtObj
> > Debug.Print
> > --
> > HTH,
> > Barb Reinhardt
> >
> >

>
>
>

 
Reply With Quote
 
Andy Pope
Guest
Posts: n/a
 
      10th Sep 2008
Hi,

What exactly do you want the function to do?

Currently it checks all the chartobjects on a sheet to see if the
topleftcell they cover is within the print area.
As soon as a chart meets that requirement the loop terminates. This could
lead to incorrect results.

Cheers
Andy

--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
"Barb Reinhardt" <(E-Mail Removed)> wrote in message
news:7281A7D4-9777-471F-AD93-(E-Mail Removed)...
> I'm trying to determine if a ChartObject is within the Print_Area on a
> given
> worksheet and have this code. I've noted in the code where execution
> ends.
> I've done a "debug.print" and see that the topleftcell is in the
> Print_area,
> but I'm not sure why it's quitting on me. Does anyone have any ideas?
>
>
> Dim ChtObj As Excel.ChartObject
> Dim myRange As Range
>
> myChartInRange = False
>
>
> On Error Resume Next
> Set myRange = myWS.Range("Print_Area")
> On Error GoTo 0
> If myRange Is Nothing Then Exit Sub
>
> For Each ChtObj In myWS.ChartObjects
> myChartInRange = False
> 'Execution in this sub ends on the line below
> If Not Intersect(ChtObj.TopLeftCell, myRange) Is Nothing Then
> Debug.Print "Top Left in Range", myWS.Name, ChtObj.Name
> Set myChtObj = ChtObj
> myChartInRange = True
> Exit For
> End If
> Next ChtObj
> Debug.Print
> --
> HTH,
> Barb Reinhardt
>
>


 
Reply With Quote
 
Barb Reinhardt
Guest
Posts: n/a
 
      10th Sep 2008
My problem was that I was doing this in PowerPOint and didn't use the
XLApp.Intersect function.

Thanks for your help.
Barb Reinhardt




"Jon Peltier" wrote:

> Barb -
>
> I ran this fine in 2003 (SP3) and 2007 (SP1). I don't think I changed
> anything meaningful.
>
> I used this sub to test the function in 2003 and 2007. In all cases I got
> True or False in the debug window and the beep at the end of the function. I
> don't know why you had problems, unless it's related to some fixes made in
> SP1.
>
> Sub test()
> Debug.Print myChartInRange
> End Sub
>
> This is the function. I don't think I changed anything meaningful from what
> you posted.
>
> Function myChartInRange()
> Dim myWS As Worksheet
> Dim ChtObj As Excel.ChartObject
> Dim myChtObj As Excel.ChartObject
> Dim myRange As Range
>
> myChartInRange = False
> Set myWS = ActiveSheet
>
> On Error Resume Next
> Set myRange = myWS.Range("Print_Area")
> On Error GoTo 0
> If myRange Is Nothing Then Exit Function
>
> For Each ChtObj In myWS.ChartObjects
> myChartInRange = False
> 'Execution in this sub ends on the line below
> If Not Intersect(ChtObj.TopLeftCell, myRange) Is Nothing Then
>
> Debug.Print "Top Left in Range", myWS.Name, ChtObj.Name
> Set myChtObj = ChtObj
> myChartInRange = True
> Exit For
>
> End If
> Next ChtObj
> Beep
> End Function
>
>
> - Jon
> -------
> Jon Peltier, Microsoft Excel MVP
> Tutorials and Custom Solutions
> Peltier Technical Services, Inc. - http://PeltierTech.com
> _______
>
>
> "Barb Reinhardt" <(E-Mail Removed)> wrote in message
> news:7281A7D4-9777-471F-AD93-(E-Mail Removed)...
> > I'm trying to determine if a ChartObject is within the Print_Area on a
> > given
> > worksheet and have this code. I've noted in the code where execution
> > ends.
> > I've done a "debug.print" and see that the topleftcell is in the
> > Print_area,
> > but I'm not sure why it's quitting on me. Does anyone have any ideas?
> >
> >
> > Dim ChtObj As Excel.ChartObject
> > Dim myRange As Range
> >
> > myChartInRange = False
> >
> >
> > On Error Resume Next
> > Set myRange = myWS.Range("Print_Area")
> > On Error GoTo 0
> > If myRange Is Nothing Then Exit Sub
> >
> > For Each ChtObj In myWS.ChartObjects
> > myChartInRange = False
> > 'Execution in this sub ends on the line below
> > If Not Intersect(ChtObj.TopLeftCell, myRange) Is Nothing Then
> > Debug.Print "Top Left in Range", myWS.Name, ChtObj.Name
> > Set myChtObj = ChtObj
> > myChartInRange = True
> > Exit For
> > End If
> > Next ChtObj
> > Debug.Print
> > --
> > HTH,
> > Barb Reinhardt
> >
> >

>
>
>

 
Reply With Quote
 
Barb Reinhardt
Guest
Posts: n/a
 
      10th Sep 2008
Based on the way this is used, it's not a problem. I was trying to use an
Excel function within powerpoint and it kept kicking me out until I figured
that out.
Thanks,
Barb Reinhardt




"Andy Pope" wrote:

> Hi,
>
> What exactly do you want the function to do?
>
> Currently it checks all the chartobjects on a sheet to see if the
> topleftcell they cover is within the print area.
> As soon as a chart meets that requirement the loop terminates. This could
> lead to incorrect results.
>
> Cheers
> Andy
>
> --
>
> Andy Pope, Microsoft MVP - Excel
> http://www.andypope.info
> "Barb Reinhardt" <(E-Mail Removed)> wrote in message
> news:7281A7D4-9777-471F-AD93-(E-Mail Removed)...
> > I'm trying to determine if a ChartObject is within the Print_Area on a
> > given
> > worksheet and have this code. I've noted in the code where execution
> > ends.
> > I've done a "debug.print" and see that the topleftcell is in the
> > Print_area,
> > but I'm not sure why it's quitting on me. Does anyone have any ideas?
> >
> >
> > Dim ChtObj As Excel.ChartObject
> > Dim myRange As Range
> >
> > myChartInRange = False
> >
> >
> > On Error Resume Next
> > Set myRange = myWS.Range("Print_Area")
> > On Error GoTo 0
> > If myRange Is Nothing Then Exit Sub
> >
> > For Each ChtObj In myWS.ChartObjects
> > myChartInRange = False
> > 'Execution in this sub ends on the line below
> > If Not Intersect(ChtObj.TopLeftCell, myRange) Is Nothing Then
> > Debug.Print "Top Left in Range", myWS.Name, ChtObj.Name
> > Set myChtObj = ChtObj
> > myChartInRange = True
> > Exit For
> > End If
> > Next ChtObj
> > Debug.Print
> > --
> > HTH,
> > Barb Reinhardt
> >
> >

>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Determining the Active Worksheet ordnance1 Microsoft Excel Programming 2 15th Apr 2010 08:04 PM
Test whether a chartobject is on a worksheet Werner Rohrmoser Microsoft Excel Programming 5 8th Apr 2008 11:59 AM
How to find existing ChartObject in a worksheet? itdept Microsoft Excel Programming 1 8th Feb 2007 03:09 PM
Determining selected worksheet Bob Conar Microsoft Excel Programming 3 20th Oct 2003 01:51 AM
Determining if a worksheet exists within a workbook Cory Schneider Microsoft Excel Programming 1 17th Jul 2003 12:36 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:54 AM.