View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
ben ben is offline
external usenet poster
 
Posts: 232
Default Stepping through Code

that is exceedingly unusual, adding a Range.select statement cleared up the
problem, sounds like this may be a BUG. Thanks for the workaround Nick

--
When you lose your mind, you free your life.


"Nick Hebb" wrote:

I've had this type of problem a number of times when working with
AutoShapes - works in step-through, but throws an error when running
normally.

The tricks I've resorted to a

1. Prior to the statement, add a line:

If wks Is Nothing Then
MsgBox "blah blah blah"
Exit Sub
End If

2. Add an "On Error Resume Next" prior to the statement, then check the
error number after:

If Err.Number < 0 Then
MsgBox "blah blah blah"
Exit Sub
Else
On Error Goto Err_Handler
End If

3. Check the existence of the shape after the AddShape method:

If sh Is Nothing Then
MsgBox "blah blah blah"
Exit Sub
End If


4. Select something before or after the operation - a range or shape -
depending upon what you're doing.

Strangely, adding these items often makes the errors go away, although
you really haven't done anything other than check for the existence of
objects or errors. It's as though it gives Excel a "chance to catch
up".

HTH,

Nick Hebb