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

I have a large number of similar spreadsheets which have
the following code in the code modules of all worksheets
in the workbook that are not named "Overview":

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Application.Run "ESCode.xls!WorksheetCode.PanelsChange"
End Sub


I want to add ", Target" to the end of this line, and have
tried the following code:


For Each sh In Worksheets
If sh.name < "Overview" Then
Set VBCodeMod = ActiveWorkbook.VBProject.VBComponents_
(sh.index).CodeModule
With VBCodeMod
.DeleteLines 2
.InsertLines 2, " Application.Run ""ESCode.xls!
_WorksheetCode.PanelsChange"", Target"
End With
End If
Next


At first, all seemed well, but then I discovered that the
code in the last worksheet had not changed (all others
had). Further, a section of code that is called when
closing the file stopped working at the following line:


If Workbooks(counter).Worksheets(1).name = "Overview" Then


Msgboxing Workbooks(counter).name and Worksheets(1).name,
I found that Workbooks(counter).name correctly gave the
name of the workbook, but Worksheets(1).name gave a run-
time error. As far as I can tell, this section of code is
in no way related to the code above, but it has worked for
years until I made the changes to the worksheet code.


If anyone can shed some light on this...?

Windows 2000, Excel 97.

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
adding an autoshape to vba code NG Excel Discussion (Misc queries) 0 October 19th 09 07:44 PM
code to prevent users from adding new worksheets jat Excel Worksheet Functions 2 March 18th 09 08:24 PM
Adding code to a macro Excel Helps Excel Worksheet Functions 2 January 23rd 08 06:15 PM
adding and subtracting using vb code ASU Excel Discussion (Misc queries) 2 October 7th 06 09:48 AM
Need code to protect worksheets - amount of worksheets varies Sandy[_3_] Excel Programming 1 September 9th 03 02:17 AM


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

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

About Us

"It's about Microsoft Excel"