Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default VBCodeMod crashing Excel

Excel97 Win2000


I have a large number of spreadsheets with VB code that I
need to modify. In each of the worksheet code modules I
want to delete the second line of code and replace it with
something else. Whenever any of these files is opened -
the file 'EScode.xls' is automatically opened, and it is
in this file that I write the code to do the update
whenever one of the spreadsheets that needs modification
is opened. I have written the following code to achieve
this:

Dim VBCodeMod As VBIDE.CodeModule

For Each sh In Worksheets
Set VBCodeMod = ActiveWorkbook.VBProject.VBComponents
(sh.index + 1).CodeModule
With VBCodeMod
.DeleteLines 2
.InsertLines 2, " Application.Run ""ESCode.xls!
WorksheetCode.PanelsChange"", Target"
End With
Next

It works the first time, but if the file (but not Excel)
is closed and reopened, it crashes at '.DeleteLines 2'
with a 'memory could not be read...' error.

The problem is repeatable - if I open Excel again, it
works the first time, crashes the second. As there are
hundreds of spreadsheets like this, having it crash on
every second one would be a major headache.

Does anyone know what might be the problem, or how to
either fix or work around it?

mgs


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default VBCodeMod crashing Excel

For anyone interested, after a week of experimenting I
think I have fixed my problem. Instead of deleting line 2
and then adding the new line 2, I add the new line 2 first
and then delete line 3. Don't know why it works, but I
won't argue.

mgs

-----Original Message-----
Excel97 Win2000


I have a large number of spreadsheets with VB code that I
need to modify. In each of the worksheet code modules I
want to delete the second line of code and replace it

with
something else. Whenever any of these files is opened -
the file 'EScode.xls' is automatically opened, and it is
in this file that I write the code to do the update
whenever one of the spreadsheets that needs modification
is opened. I have written the following code to achieve
this:

Dim VBCodeMod As VBIDE.CodeModule

For Each sh In Worksheets
Set VBCodeMod = ActiveWorkbook.VBProject.VBComponents
(sh.index + 1).CodeModule
With VBCodeMod
.DeleteLines 2
.InsertLines 2, " Application.Run ""ESCode.xls!
WorksheetCode.PanelsChange"", Target"
End With
Next

It works the first time, but if the file (but not Excel)
is closed and reopened, it crashes at '.DeleteLines 2'
with a 'memory could not be read...' error.

The problem is repeatable - if I open Excel again, it
works the first time, crashes the second. As there are
hundreds of spreadsheets like this, having it crash on
every second one would be a major headache.

Does anyone know what might be the problem, or how to
either fix or work around it?

mgs


.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
excel Crashing SJMP Setting up and Configuration of Excel 3 March 6th 09 12:27 PM
Excel Crashing [email protected] Excel Discussion (Misc queries) 1 December 10th 07 02:23 PM
Crashing of Excel FASB Excel Discussion (Misc queries) 1 June 5th 07 04:32 PM
Help--Excel keeps crashing [email protected] Excel Discussion (Misc queries) 1 September 7th 05 10:22 PM
excel keeps crashing kickyr Excel Programming 4 December 4th 03 09:58 PM


All times are GMT +1. The time now is 10:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"