ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBScript Event Sink Not Firing (https://www.excelbanter.com/excel-programming/404345-vbscript-event-sink-not-firing.html)

Alex Turner

VBScript Event Sink Not Firing
 
Anyone knows why this does not work - i.e. the even sink
excel_SheetChange never fires?

Dim myExcel,myWorkbook,mySheet

Set myExcel=WScript.CreateObject("Excel.Application"," excel_")

Set myWorkbook=myExcel.Workbooks.Add()
Set mySheet=myWorkbook.Sheets(1)
myExcel.Visible=TRUE

myExcel.EnableEvents=TRUE

While myExcel.Visible
WScript.Sleep(100)
Wend

Sub excel_SheetChange(ByVal Sh, ByVal Target)
WScript.Echo "Sheet Change: Sheet=" & Sh.Name & ", Range=" &
Target.Row & "," & Target.Column
End Sub

Any help welcome. If I get this to work I'll be posting about it on my
blog. I've been wanting to sink Excel events to vbscript for ages and
just don't seem to be able to manage :(

Thanks!

AJ

--
http://nerds-central.blogpot.com

joel

VBScript Event Sink Not Firing
 
1) Make sure the worksheet_change function is on the VBA sheet where you want
it to work. Work_sheet change fucntion only works on one sheet
2) Worksheet_change get only one parameter, not two
3) To get the sheetname use activesheet

Sub worksheet_Change(ByVal Target As Range)
MsgBox "Sheet Change: Sheet=" & ActiveSheet.Name & _
", Range=" & Target.Row & "," & Target.Column
End Sub


"Alex Turner" wrote:

Anyone knows why this does not work - i.e. the even sink
excel_SheetChange never fires?

Dim myExcel,myWorkbook,mySheet

Set myExcel=WScript.CreateObject("Excel.Application"," excel_")

Set myWorkbook=myExcel.Workbooks.Add()
Set mySheet=myWorkbook.Sheets(1)
myExcel.Visible=TRUE

myExcel.EnableEvents=TRUE

While myExcel.Visible
WScript.Sleep(100)
Wend

Sub excel_SheetChange(ByVal Sh, ByVal Target)
WScript.Echo "Sheet Change: Sheet=" & Sh.Name & ", Range=" &
Target.Row & "," & Target.Column
End Sub

Any help welcome. If I get this to work I'll be posting about it on my
blog. I've been wanting to sink Excel events to vbscript for ages and
just don't seem to be able to manage :(

Thanks!

AJ

--
http://nerds-central.blogpot.com


Robert Bruce

VBScript Event Sink Not Firing
 
Yn newyddion: ,
Roedd Alex Turner wedi ysgrifennu:

Anyone knows why this does not work - i.e. the even sink
excel_SheetChange never fires?


VBScript supports only late binding. In order to sink COM events you need to
early bind and use the WithEvents declaration in a class module.

Rob


Robert Bruce

VBScript Event Sink Not Firing
 
Yn newyddion: ,
Roedd Alex Turner wedi ysgrifennu:

I think you'll find that what you've said is not actually try. See
WScript.CreateObject and WScript.ConnectObject. There seems something
different about Excel it is definitely possible to sink events to
VBScript with other objects, like IE etc.


Sorry Alex. You're right and I;m wrong.

Rob

papou[_4_]

VBScript Event Sink Not Firing
 
Hello Alex

Not a VBScript expert and probably not to be considered as an excel "guru".
Nevertheless I would suggest that you can hardly fire your sub to run a
workbook event procedure (Workbook_SheetChange in your case) from an Excel
application object, since no event procedure is present in the workbook
(remember you are creating a new workbook).
The only possible alternative I can see is to create, via your script, the
event procedure in the new workbook.

HTH
Cordially
Pascal


"Alex Turner" a écrit dans le message de news:
...
Anyone knows why this does not work - i.e. the even sink
excel_SheetChange never fires?

Dim myExcel,myWorkbook,mySheet

Set myExcel=WScript.CreateObject("Excel.Application"," excel_")

Set myWorkbook=myExcel.Workbooks.Add()
Set mySheet=myWorkbook.Sheets(1)
myExcel.Visible=TRUE

myExcel.EnableEvents=TRUE

While myExcel.Visible
WScript.Sleep(100)
Wend

Sub excel_SheetChange(ByVal Sh, ByVal Target)
WScript.Echo "Sheet Change: Sheet=" & Sh.Name & ", Range=" &
Target.Row & "," & Target.Column
End Sub

Any help welcome. If I get this to work I'll be posting about it on my
blog. I've been wanting to sink Excel events to vbscript for ages and
just don't seem to be able to manage :(

Thanks!

AJ

--
http://nerds-central.blogpot.com




All times are GMT +1. The time now is 12:06 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com