I'm trying to produce some simple shapes in a workbook when a button is pressed. Ill be adding more code to later on to manipulate the shapes.
I have a list in the worksheet cell AA1 to AA5 as follows Type Name
bar __bar_2 20 120
bar __bar_1 10 100
point __point_1 2 2
pin __pin_1 8 2
The bars appear in the worksheet fine but when I added code for the point and pin the code wont run
The code is as follows
Private Sub CommandButton1_Click()
list_top = "AA1"
For i = 1 To 100000
shape_type = Range(list_top).Offset(i, 0).Value
If shape_type = "" Then Exit Sub
Select Case shape_type
Case "bar"
new_bar Range(list_top).Offset(i, 1).Value, Range(list_top).Offset(i, 2).Value, Range(list_top).Offset(i, 3).Value
Case "point"
new_point Range(list_top).Offset(i, 1).Value, Range(list_top).Offset(i, 2).Value, Range(list_top).Offset(i, 3).Value
Case "pin"
new_pint Range(list_top).Offset(i, 1).Value, Range(list_top).Offset(i, 2).Value, Range(list_top).Offset(i, 3).Value
End Select
Next i
End Sub
with module
Public Sub new_bar(ByVal bar_name As String, ByVal bar_width As Double, bar_length_pin_to_pin As Double)
ActiveSheet.Shapes("_bar").Duplicate
DoEvents
ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Name = bar_name
ActiveSheet.Shapes(bar_name).Height = bar_width
ActiveSheet.Shapes(bar_name).Width = bar_width + bar_length_pin_to_pin
End Sub
Public Sub new_point(ByVal point_name As String)
ActiveSheet.Shapes("_point").Duplicate
DoEvents
ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Name = point_name
ActiveSheet.Shapes(point_name).Height = point_width
ActiveSheet.Shapes(point_name).Width = point_diameter
End Sub
Public Sub new_pin(ByVal pin_name As String, ByVal pin_diameter As Double)
ActiveSheet.Shapes("_pin").Duplicate
DoEvents
ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Name = pin_name
ActiveSheet.Shapes(point_name).Height = pin_width
ActiveSheet.Shapes(point_name).Width = pin_width
End Sub
Not sure what the problem is, probably something simple? I haven't been using VBA very long
Thanks Paul
Bookmarks