View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Nick Hebb Nick Hebb is offline
external usenet poster
 
Posts: 162
Default Stepping through Code

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