Consulting

Results 1 to 6 of 6

Thread: Assigning two macros to one shape to run on different actions

  1. #1
    VBAX Regular
    Joined
    Oct 2017
    Posts
    8
    Location

    Question Assigning two macros to one shape to run on different actions

    Hi everyone,
    It's my first post here (woo) so please bear with me if I don't get this right!

    Basically I want to assign two macros to one shape, one that will run on a single click (as per usual) and one that will run on something else such as a double click or right click.

    I've tried looking into events and the worksheet_beforedoubleclick event but am really struggling to assign it to the shape.

    Does anyone have any advice/ done this before?

    Thanks in advance!!
    Last edited by rosalie; 10-24-2017 at 08:02 AM.

  2. #2
    SHapes can only respond to one assigned macro which runs at click. If you need more "events, add an ActiveX control to your sheet, which have a number of events available such as mouseup/down, keyup/down, mousemove, right-click, click, ...
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    The easiest way I know would be to click the shape holding down a shift key or not holding down a shift key

    As Jan said, the shape can only respond to one macro, but THAT macro can respond to shift key status


    Sub ShapeMacro()
        If IsShiftKeyDown Then
            Macro1
        Else
            Macro2
        End If
    End Sub
    
    
    Sub Macro1()
        MsgBox "Shift Key macro"
    End Sub
    
    
    Sub Macro2()
        MsgBox "Not Shift Key macro"
    End Sub

    The rest of the code is in the attachment (not original with me, but I didn't make a reference where I 'borrowed' it so apologies to the originator)
    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

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,875
    Quote Originally Posted by rosalie View Post
    so please bare with me if I don't get this right!
    I'll keep my clothes on if that's all right.

  5. #5
    VBAX Regular
    Joined
    Oct 2017
    Posts
    8
    Location
    oops my bad!

  6. #6
    VBAX Regular
    Joined
    Oct 2017
    Posts
    8
    Location
    Thank you so Paul much this absolutely worked!!!

Tags for this Thread

Posting Permissions

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