PDA

View Full Version : Solved: Select the shape as shape variable



jignesh142
10-14-2012, 11:34 PM
i have worksheet, in which i have many shapes
i have defined one variable oShape1 as shape
now i select anyone shape form the worksheet and assign that shape to the oShape1 variable that i defined
how can i do that?

Bob Phillips
10-15-2012, 12:46 AM
Set oShape1 = ActiveSheet.Shapes(Selection.Name)

jignesh142
10-15-2012, 11:46 PM
Thanks for your replay.
Actually i have created the program for creating arrow between two shapes.
For that i have created three command button, one for assigning the shape1, second for assigning shape2 and third for creating arrow between that two shapes. When i activate the command button three for creating arrow between shapes it says that oShape1,oShape2 holds nothing.
First shape is selected and command button3 clicked and then second shape is selected and command button4 is clicked, and then finally command button 2 is clicked to created arrow but it says that oShape1 and oShape2 holds nothing
Here is my code


Private Sub CommandButton3_Click()
Dim oShape1 As Shape
Set oShape1 = ActiveSheet.Shapes(Selection.Name)
End Sub

Private Sub CommandButton4_Click()
Dim oShape2 As Shape
Set oShape2 = ActiveSheet.Shapes(Selection.Name)
End Sub

Private Sub CommandButton2_Click()
Dim oShape1 As Shape
Dim oShape2 As Shape
Dim oConnector As Shape
Set oConnector = AddConnectorBetweenShapes(msoConnectorStraight, oShape1, oShape2)
oShape1 = Nothing
oShape2 = Nothing

End Sub

Bob Phillips
10-16-2012, 12:16 AM
They are different variables in different procedures.


Dim oShape1 As Shape
Dim oShape2 As Shape

Private Sub CommandButton3_Click()
Set oShape1 = ActiveSheet.Shapes(Selection.Name)
End Sub

Private Sub CommandButton4_Click()
Set oShape2 = ActiveSheet.Shapes(Selection.Name)
End Sub

Private Sub CommandButton2_Click()
Dim oConnector As Shape
Set oConnector = AddConnectorBetweenShapes(msoConnectorStraight, oShape1, oShape2)
oShape1 = Nothing
oShape2 = Nothing

End Sub

jignesh142
10-16-2012, 01:13 AM
You made my day !!!

Many Thanks for the Help..It worked Now

Sometimes silly mistake blocks whole program !!!!