Thread: Timing Issue??
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Vasant Nanavati Vasant Nanavati is offline
external usenet poster
 
Posts: 1,080
Default Timing Issue??

ThisWorkbook refers to the workbook containing the code. You need to specify
the specific workbook that you want to operate on.

--

Vasant


"Geoff" wrote in message
...
Hi
I am trying to adapt Chip Pearson's code and insert the same procedure
into
2 added worksheets.

Strange thing is my code only fails each time I start a new instance of
the
workbook. Even then, when the code breaks on error with 'Subscript out of
Range' and I click to continue in Debug mode the code completes without
error
AND the new module is installed correctly in both new worksheets.

Within the same instance of the workbook and beyond the initial 'block'
the
procedure works without hesitation repeatedly. When creating the second
of
the 2 worksheets, the code never fails whether it is in the first instance
of
the workbook or not.

The fact that the identical code works on the second worksheet insert and
works repeatedly thereafter (within the same wb instance) suggests a
compile
timing problem but how do I get around it?
The code fails at *** with Subscript out of Range...

Sheets.Add After:=Sheets(Sheets.Count)
Set ws = Sheets(Sheets.Count)
With ThisWorkbook.VBProject.VBComponents(ws.CodeName).C odeModule '***
.InsertLines .CountOfLines + 1, _
'required proc'
End With

What am I missing? I would appreciate any help.

T.I.A.

Geoff