Excel VBA check if chart is part of a group

Johnny C

Well-known Member
Joined
Nov 7, 2006
Messages
1,069
Office Version
  1. 365
Platform
  1. Windows
Hi

I'm writing an Add-In so people in my team can copy charts automatically to PowerPoint or Word.
I just tested it on a file where one of the charts has text boxed and an arrow grouped together - these will need to be copied together.

First, How do I tell that the chart is part of a Group. I can use error trapping as it will crash when I do
Code:
ActiveChart.ChartArea.Copy
if it's grouped but I'd rather do it properly if it can.

If I can tell it's in a group, I identify which Group it is part of so that I can then copy the whole group instead of the chart?

TIA
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hi

Lets say you have a chart in the active worksheet called "MyChart"

Execute this to see if it's not part of a group or if it's part of a group and, in this case, the name of the group:

Code:
Sub ChartIsPartOfGroup()
Dim chtO As ChartObject
Dim sGroup As String

Set chtO = ActiveSheet.ChartObjects("MyChart")
sGroup = ""
On Error Resume Next
sGroup = chtO.ShapeRange.ParentGroup.Name
On Error GoTo 0

MsgBox IIf(sGroup = "", "Not grouped", "Group name: " & sGroup)

End Sub
 
Upvote 0
Cheers. I was hoping to do it without error trapping but if I can get the group name I can do a prescan I guess to ID charts in groups and not in groups and deal with each separately.
 
Upvote 0

Forum statistics

Threads
1,213,511
Messages
6,114,054
Members
448,543
Latest member
MartinLarkin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top