Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel Crash in procedure.
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 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to jump from a Form procedure to a Workbook or Module procedure? | Excel Programming | |||
Excel Crash - Help! | Excel Discussion (Misc queries) | |||
Excel ADO Crash | Excel Programming | |||
Opening a UserForm causes a crash in the Exit procedure (Which is never called) | Excel Programming |