Consulting

Results 1 to 12 of 12

Thread: How to click programmatically on a shape

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Tutor
    Joined
    Jun 2005
    Posts
    214
    Location

    How to click programmatically on a shape

    Hi,

    Is it possible to click (not to select) programmatically on a shape in order to start a procedure (sub)?

    The code below selects the grey shape, but i need code that "click's" on it (an artificial click fired by code).

    Insert my test code below in a module and run Draw_Shapes. After clicking the red shape i want the message "My color is grey" to appear, via the grey shape.

    [vba]Sub Draw_Shapes()
    Dim sh As Shape
    For Each sh In ActiveSheet.Shapes
    sh.Delete
    Next
    ActiveSheet.Shapes.AddShape(1, Left:=ThisWorkbook.Application.Range("A1").Left + 10, Top:=ThisWorkbook.Application.Range("A1").Top + 2, Width:=50, Height:=50).Select
    Selection.Name = "GreyShape"
    Selection.OnAction = " My_Color_Is_Grey"
    With Selection.ShapeRange.Line
    .Visible = msoTrue
    .Weight = 1
    End With
    With Selection.ShapeRange.Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(150, 150, 150)
    .Transparency = 0
    .Solid
    End With
    ActiveSheet.Shapes.AddShape(1, Left:=ThisWorkbook.Application.Range("E1").Left + 10, Top:=ThisWorkbook.Application.Range("E1").Top + 2, Width:=100, Height:=50).Select
    Selection.ShapeRange.TextFrame.Characters.Text = "Click programmatically on left left"
    Selection.OnAction = "Activate_MyColorIsGrey"
    With Selection.ShapeRange.Line
    .Visible = msoTrue
    .Weight = 1
    End With
    With Selection.ShapeRange.Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(255, 0, 0)
    .Transparency = 0
    .Solid
    End With
    End Sub


    Sub My_Color_Is_Grey()
    MsgBox "My color is Grey"
    End Sub


    Sub Activate_MyColorIsGrey()
    ActiveSheet.Shapes("GreyShape").Select
    End Sub
    [/vba] Greatings,
    Stranno
    Last edited by Aussiebear; 12-07-2012 at 03:09 AM. Reason: Added tags to code

Posting Permissions

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