View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Excel Crash in procedure.

Tim: I'm worried about the network disk drive having problems. Thought if we
put the text file on the C drive it would help to isolate the cause of the
problem. There may be disk errors on the drive or the drive may be busy and
you are having a time out problem.

"Tim Rush" wrote:


The text file with the code being entered is just text. Nothing special. I
did a copy-paste of the code I wanted to use, right into notepad, saved it
normally.


"Peter T" wrote:

Set VBProj = activeworkbook.VBProject


Is the Activeworkbook same as Thisworkbook. Trying to write code to
worksheet and thisworkbook modules of the same project that's running the
code is fraught with problems.

Regards,
Peter T

"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