View Single Post
  #12   Report Post  
Posted to microsoft.public.excel.programming
Tim Rush Tim Rush is offline
external usenet poster
 
Posts: 27
Default Excel Crash in procedure.

Ok, the Sleep idea makes a a little sense. Certainly won't hurt anything,
I'm looking at 3 seconds of code anyway.

Here is a bit that I just noticed though...
I'm writing code to 2 modules so I'm running through the procedure twice.
The Excel dump appears to happen (most often) after the second module is
written.
Does not seem to matter which order I put them in.
One is a sheet module, the other is the 'ThisWorkbook' module.
Running just one (either one) does not give me any problems during the 20 or
so times I ran it.

Sad thing is, by the time we figure it out, I probably could have done the
200 or so files by hand (: , although i have further use for it after this.

"Peter T" wrote:

That's interesting but I'm surprised that makes any difference. As soon as
you start writing new lines the project is no longer fully compiled.

Regards,
Peter T


"Tim Zych" <tzych@NOSp@mE@RTHLINKDOTNET wrote in message
...
One thing I've noticed while importing code, especially for large

projects,
is that Excel can and does crash if the project is not compiled first. My
personal preference is not to use code that writes code in a production
environment for a number of reasons, but for personal use, definitely.
Compiling the project where the code is going before running the import
macro has been a reliable prerequisite for me. Perhaps this is why it

works
for you sometimes, because the compiler was happy 3 out of 10 times you

ran
it.

--
Tim Zych
www.higherdata.com
Compare data in worksheets and find differences with Workbook Compare
A free, powerful, flexible Excel utility


"Tim Rush" wrote in message
...
The procedure below works sometimes and sometimes not.
This is basically Chip Pearson's vbProject routines.
Everything works fine initializing all vb objects and beginning the add
procdure. Apparently I get the entire text file entered, then (stepping
through procdure) when the End With is highlighted just above the LOOP,
Excel does a complete dump and error recovery.
Happens 7 out of 10 times, the other times, it works fine, so that makes
it
hard to figure out.
I'm using Excel2003, winXP
I do have the extendability library on per Chip
If somebody would like the whole file, I can zip and upload a

declassified
version.

Private Sub AddProcedureToModule()
Dim module As String 'These lines added to test procedure only
module = "OVL"
'
'
On Error GoTo ErrorTrap
'Private Sub AddProcedureToModule(module As String) 'Procedure from Chip
Pearson
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim objFSO As Object
Dim objFile As Object
Dim LineNum As Long
Dim Source As String
Dim EntryLine As String
Const DQUOTE = """" ' one " character
Source = "Y:\Quality\ovlSetup\" & module & ".txt" 'location of

code
to enter
Set VBProj = activeworkbook.VBProject
'Set VBComp = VBProj.VBComponents(module)
Set VBComp = VBProj.VBComponents(Worksheets(module).CodeName)
'modification by Dave Peterson
Set CodeMod = VBComp.CodeModule
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(Source, 1)
Do Until objFile.AtEndOfStream
EntryLine = objFile.readline
With CodeMod
LineNum = .CountOfLines + 1
.InsertLines LineNum, EntryLine
End With
Loop
ExitHe
objFile.Close
Set objFSO = Nothing
Set objFile = Nothing
Exit Sub
ErrorTrap: 'added brief error handling
MsgBox ("Error in AddProcedure routine.") 'informs which

procedure
to debug
'useful with on error
resume next
GoTo ExitHe
End Sub