View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
r r is offline
external usenet poster
 
Posts: 125
Default Insert Worksheet change procedure

the routine, I work regularly
what's on wsEvent

regards
r

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


"ojv" wrote:

There are no error number or description. Excel just tells me it crashed,
needs to shut down, will restore my documents and asks the usual question of
wether I want to send an error report to MS.

regards
ojv

"r" wrote:

that error you get?
number and description please
regards
r

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


"ojv" wrote:

Thx for responding. I already have a reference to the extensibility lib. The
runtime crash occurs after execution of

pos = vbc.CodeModule.CreateEventProc("Change", "Worksheet")

before the statement inserting body text.
I am able to insert a number of different events like workbook events, but
this one fails. I just do not understand why.

ojv

"r" wrote:

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