Question : Excel - Insert msoAutoShape

Hi All,
I have a list of Shape-names (msoShape16pointStar, msoShapeSun,
msoShapeArc, msoShapeQuadArrow, .......)  in A2:A140
and would like to create the corresponding Shapes in B2:B140 .

I have tried the following macro:

Sub Insert_Shapes()
Dim list As Range
Dim listArray()
Dim num As Integer
Dim i As Integer

Set list = Sheets(1).Range("a2:a140")
num = WorksheetFunction.CountA(list)
ReDim listArray(1 To num)

For i = 1 To num
    listArray(i) = Range("a" & i + 1)
    ActiveSheet.Shapes.AddShape listArray(i), 250, 2 + i * 12.75, 8, 8
' ==> Error 13 happens here
    'ActiveSheet.Shapes.AddShape msoShape16pointStar, 250, 2 + i *
12.75, 8, 8
Next i
End Sub

I have tried lots of different DIM-declarations for 'listArray'
but none seems to work.
On the first stepping through the macro I  get an error as follows:
    Run-time error '13': Type mismatch.
This despite the fact that the value of list Array(1) is showing the
exact value (.i.e msoShape16pointStar).

I have found that if I change my list in A2:A140 from the
shape-names to the corresponding Shape-Constants,
the macro works correctly as intended. Hovever a value
of '94' is less  informative than a description like
'msoShape16pointStar', thus I would
like to make this work with the Shape-names as well.

Answer : Excel - Insert msoAutoShape

Oops! Wrong code in loop:

   ActiveSheet.Shapes.AddShape listshapes(1)(Application.Match(listArray(i), listshapes(0), 0)), 250, 2 + i * 12.75, 8, 8

Suat
Random Solutions  
 
programming4us programming4us