LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
r r is offline
external usenet poster
 
Posts: 125
Default Insert Worksheet change procedure

Sub AddEvents()
Dim vbc As VBComponent, pos As Long, body As String
'with reference to
'Microsoft visual basic for applications extensibility 5.x
For Each vbc In ActiveWorkbook.VBProject.VBComponents
If vbc.Name = Worksheets(1).CodeName Then
pos = vbc.CodeModule.CreateEventProc("Change", "Worksheet")
body = "test"
vbc.CodeModule.InsertLines pos, body
Exit For
End If
Next
End Sub


Sub AddEvents2()
Dim vbc, pos As Long, body As String
'no reference
'Microsoft visual basic for applications extensibility 5.x
For Each vbc In ActiveWorkbook.VBProject.VBComponents
If vbc.Name = Worksheets(1).CodeName Then
pos = vbc.CodeModule.CreateEventProc("Change", "Worksheet")
body = "test"
vbc.CodeModule.InsertLines pos, body
Exit For
End If
Next
End Sub


regards
r


Il mio ultimo lavoro ...
http://excelvba.altervista.org/blog/...ternative.html


"ojv" wrote:

I get a runtime error in Excel using the following method:

Sub AddEvents()
Dim vbc As VBComponent, pos As Long, body as String

For Each vbc In ActiveWorkbook.VBProject.VBComponents
If vbc.name = Worksheets(1).codeName Then
pos = vbc.CodeModule.CreateEventProc("Change", "Worksheet")
body = wsEvent
vbc.CodeModule.InsertLines pos, body
Exit For
End If
Next
End Sub

What am i doing wrong?
Any help appreciated
ojv

 
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
Run procedure from worksheet change event ranswert Excel Programming 1 January 17th 08 07:49 PM
Validation Procedure with a worksheet change event Bhupinder Rayat Excel Worksheet Functions 2 October 3rd 07 05:18 PM
If I insert a row in my worksheet, I have to change the row manua Paul Excel Programming 1 April 22nd 06 02:23 PM
Excel locks with Worksheet Change procedure Casey[_62_] Excel Programming 0 March 22nd 06 03:14 PM
Worksheet change sub procedure Grant Excel Programming 5 September 24th 04 01:44 AM


All times are GMT +1. The time now is 04:08 AM.

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"