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

Originally it was on the C: drive. Had the problem at then as well. I moved
everything to a mapped drive so I can use it remotely later. Although I will
update all master files from here, I'll end up going on the shop floor and
upgrading the working copies, (although not as many), remotely.


"Joel" wrote:


There is something wrong with the text file or with the way windows is
getting the text file. Try putting the text file on the C: drive instead of
the Y: drive and see if you get the same problem.


"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