Consulting

Results 1 to 5 of 5

Thread: How to get Shape name based on user selection (As a variant)

  1. #1
    VBAX Newbie
    Joined
    Jan 2021
    Posts
    4
    Location

    How to get Shape name based on user selection (As a variant)

    Hello everyone,
    First time being on this forum. I am an avid user of VBA especially with Excel and Visio. I don't know if this has been asked yet but i need help in grabbing the name or id of a user selected shape, in an active powerpoint slide. I want to display a message in case a user clicks a particular shape, with names "Increase" or "Reduce". I set up my code in a SELECT CASE format and i am trying to capture the selected shape as a variant and assign it to my shape object, however i don't get any results. Here is my code. Please and thank you

    Sub determineShapeType()
    Dim osld As Slide
    Dim slideNum As Integer
    Dim Userselection As Variant
    Dim oshp As Shape


    osld = ActivePresentation.SlideShowWindow.View.Slide
    Set Userselection = ActiveWindow.Selection.Shaperange
    Set oshp = osld.Shapes(Userselection.Name)

    Select Case oshp.Name
    Case "Increase"
    MsgBox " You have increased your speed"
    'Something else
    Case "Reduce"
    MsgBox "You have decreased your speed"
    'Something else
    End Select
    End Sub

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Posts
    7,682
    Location
    I usually use the Selection Pane to rename them to something meaningful, and Insert, Action to associate clicking a shape with a macro
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Master
    Joined
    Feb 2007
    Posts
    1,963
    Location
    If you are in show mode then you cannot have a Selection. You can only select in edit mode.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  4. #4
    VBAX Newbie
    Joined
    Jan 2021
    Posts
    4
    Location
    Hmm right you are. I can see to it that i use another means

  5. #5
    VBAX Newbie
    Joined
    Jan 2021
    Posts
    4
    Location
    Thank you very much. I will definitely try your suggestion and give a reply

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •