Avatar of dlmille
dlmille
Flag for United States of America asked on

What control would I use to get chart selection?

I'm writing an addin, where the user has to select a chart, and then select a range (two different entries).  What control would I use on a userform to enable the user to select a chart (and get that value - e.g., "Chart 1" on a particular sheet - or for that matter, an active chart on a chart sheet?

Thanks!

Dave
Microsoft Excel

Avatar of undefined
Last Comment
dlmille

8/22/2022 - Mon
SiddharthRout

You can pop up a message telling the user to select a chart and after that you can use the selection object to interact with the chart?

Sid
SiddharthRout

For selecting different Range, you can use the RefEdit Control.

Sid
dlmille

ASKER
Possibly - since this is top of mind for you, how would I test the selection to ensure it was a chart they had selected?

Dave
Your help has saved me hundreds of hours of internet surfing.
fblack61
SiddharthRout

You can use the TypeName(Selection)

Sid
SiddharthRout

Example

'~~> Checks if selection is a valid chart
Sub Sample()
    On Error GoTo Err
    If TypeName(Charts(Selection.Parent.Name)) = "Chart" Then _
    Debug.Print "You have selected a Chart Sheet"
Err:
    If TypeName(Selection) = "ChartArea" Then
        Debug.Print "You have selected a Chart in a Sheet"
    Else
        Debug.Print "Invalid Selection"
    End If
End Sub

Open in new window


Sid
SiddharthRout

Forgot the exit sub before Err:

Sid
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
SiddharthRout

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
dlmille

ASKER
Thanks again!