Problem with Shape Names containing punctuation

P

Peter T

My routine to create an object of multiple shapes fails if any shape name
includes punctuation, eg

"My.Rectangle 1"

Sub TestMultiObject()
Dim cnt As Long, i as Long
Dim ob As Object

With ActiveSheet.Shapes
cnt = .Count
ReDim vArr(1 To cnt)
For i = 1 To cnt 'don't want to use "For Each"
vArr(i) = .Item(i).Name
Next
End With

'fails if any shape Name includes a dot
Set ob = ActiveSheet.DrawingObjects(vArr)

'always works
'Set ob = ActiveSheet.Shapes.Range(vArr)

MsgBox ob.Count
End Sub

I don't know why I have this problem with punctuation in shape names. First
question - does anyone else have same problem, or rather not replicate this
problem.

I have a convoluted reason for not wanting to use the line that "always
works".

Assuming this affects all users/versions, does anyone know how to create a
multiple object at the "DrawingObjects" level that caters for the
possibility of a name including punctuation.

TIA,
Peter T
 
G

Guest

I have used shapes with names containing punctuation, but never access them
by name in an array. Try accessing by index instead.
Try this:

With ActiveSheet.Shapes
cnt = .Count
ReDim vArr(1 To cnt)
For i = 1 To cnt 'don't want to use "For Each"
'vArr(i) = .Item(i).Name
vArr(i) = i ' Changes to use index instead of name.
Next
End With

'fails if any shape Name includes a dot
Set ob = ActiveSheet.DrawingObjects(vArr)

Carlos Lozano
CAX IT Services
www.caxonline.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top