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

there is only one sheet in the workbook being referenced, and this code is
running from an add-on where ALL references are qualified

the actuall line that errors out is

Set sh = wks.Shapes.AddShape(msoShapeDownArrow, 354.75, 162 + (RowN * 21),
24, 30)


sh is a public shared variable referring to a Shape
and
wks is a worksheet object that is passed into the sub and is the same
whether stepping through or at Run Time

Sub AddShape(RowN As Integer, wks As Worksheet)



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


"Tom Ogilvy" wrote:

Sounds like you are doing something on a sheet other than the sheet where
the change event occured.

If this is the case, unqualified references such as

Range("B9").Select
would refer to the worksheet that contains the code, not the active sheet if
that were a different sheet. In that type of situation, you would be
intending to select on the activesheet, but the code thinks you want to
select on the worksheet that contains the code. You can't select on a sheet
unless it is the activesheet.

So for example

In the Sheet2 code module code like

Private Sub Worksheet_Change(ByVal Target As Range)

worksheets("Sheet1").Activate
Range("B9").Select '<== 1004 error here


End Sub

better (don't select, but)

Private Sub Worksheet_Change(ByVal Target As Range)
with worksheets("Sheet1")
.Activate
.Range("B9").Select
End with
End Sub

If this isn't exactly what you are doing, I will bet it is close and the
source of your problem.

--
Regards,
Tom Ogilvy


"ben" (remove this if mailing direct) wrote in message
...
Have a code that upon a worksheet_change event creates an AutoShape object
and inserts onto the Worksheet at a specific Location. The problem is the
code ONLY works in Step-Mode, IF I break before the object is created and
then step through it. If I let the code run without breaking it always
returns an 1004 - application or object defined error,
when it attempts to create the AutoShape.
Why would it work in Step-Mode and not in Normal RunTime?
Nothing else changes, no code, no procedures, no events, no workbooks.

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