stranno
12-05-2012, 01:35 PM
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.
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
Greatings,
Stranno
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.
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
Greatings,
Stranno