Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Strange Shapes.AddShape error

I have a function that gets called from the Worksheet_Change event.
Based on a set of conditions it adds a shape to the worksheet using a
function like this:

Set newShape = ws.Shapes.AddShape(shapeType, l, t, w, h)

where ws is a Worksheet object and shapeType is a msoAutoShapeType
variable.

In general it works fine. But while doing some testing I came across a
strange (to me) error. If I add a number of shapes to the worksheet,
then delete one, subsequent calls to this function raise an error.

The error is 434 - object required.

Here's the weirdness:
- The shape gets properly created
- Debug.Assert Not(ws is Nothing) checks out fine
- Debug.Assert Not(ws.Shapes is Nothing) checks out fine
- Debug.Print ws.Shapes.Count spits out the proper shape count before
and after the line.

So I'm not sure which 'object' it's referring to since they all seem to
be there and are visible is the Locals window when debugging.

Any ideas?

Thanks,

Nick Hebb

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Strange Shapes.AddShape error

Hi Nick,

I cannot recreate your error despite some vigorous testing (below). Wild
guess, have you been renaming shapes with default type names that previously
existed. Eg, delete "AutoShape 1" and rename another as "AutoShape 1".
Although I can't directly relate to your issue, doing that can cause
unexpected problems.

Regards,
Peter T


Function fNewShape(ws As Worksheet, _
shapeType&, l#, t#, w#, h#) As Boolean
Dim newShape As Shape

Set newShape = ws.Shapes.AddShape(shapeType, l, t, w, h)

End Function

Sub test()
Dim l#, t#, h#, w#
Dim i&, n&, nType&, nDel&
Dim ws As Worksheet

Set ws = ActiveSheet
ws.Cells.Interior.ColorIndex = 40
ws.DrawingObjects.Delete
l = 18: t = 6: h = 18: w = 36

For i = 1 To (5 * 137)
n = n + 1
nType = nType + 1
fNewShape ws, nType, l, t, w, h
t = t + 30
If nType = 137 Then
nType = 0
l = l + 90
t = 6
End If
If n = 5 Then
ws.Shapes(ws.Shapes.Count).Delete
nDel = nDel + 1
n = 0
End If
Next

MsgBox ws.Shapes.Count & vbCr & nDel & vbCr & i - 1
End Sub



"Nick Hebb" wrote in message
ups.com...
I have a function that gets called from the Worksheet_Change event.
Based on a set of conditions it adds a shape to the worksheet using a
function like this:

Set newShape = ws.Shapes.AddShape(shapeType, l, t, w, h)

where ws is a Worksheet object and shapeType is a msoAutoShapeType
variable.

In general it works fine. But while doing some testing I came across a
strange (to me) error. If I add a number of shapes to the worksheet,
then delete one, subsequent calls to this function raise an error.

The error is 434 - object required.

Here's the weirdness:
- The shape gets properly created
- Debug.Assert Not(ws is Nothing) checks out fine
- Debug.Assert Not(ws.Shapes is Nothing) checks out fine
- Debug.Print ws.Shapes.Count spits out the proper shape count before
and after the line.

So I'm not sure which 'object' it's referring to since they all seem to
be there and are visible is the Locals window when debugging.

Any ideas?

Thanks,

Nick Hebb



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Got error in Shapes.AddShape() ramkumar_cpt Charts and Charting in Excel 1 March 15th 06 09:43 AM
Window Error when deleting shapes Laguna Excel Programming 1 June 10th 05 02:29 PM
.AddShape(Type, Left, Top, Width, Height) AA2e72E Excel Programming 2 February 2nd 05 01:56 PM
Error 1004 using Shapes.Range().Align juergen Excel Programming 3 June 25th 04 11:14 AM
Shapes.AddPicture run-time error Matt[_12_] Excel Programming 0 August 22nd 03 04:05 PM


All times are GMT +1. The time now is 10:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"