Link to home
Start Free TrialLog in
Avatar of dlmille
dlmilleFlag 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
Avatar of SiddharthRout
SiddharthRout
Flag of India image

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
For selecting different Range, you can use the RefEdit Control.

Sid
Avatar of 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
You can use the TypeName(Selection)

Sid
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
Forgot the exit sub before Err:

Sid
ASKER CERTIFIED SOLUTION
Avatar of SiddharthRout
SiddharthRout
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dlmille

ASKER

Thanks again!