Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default 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


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
Click event on menu item is lost after first time firing of the event [email protected] Excel Programming 1 April 2nd 07 01:25 PM
Event macro firing twice Otto Moehrbach Excel Programming 10 July 6th 05 11:57 PM
Workbook_Open event not firing 0013 Excel Programming 4 May 24th 05 09:53 PM
Event sometimes stops firing? HotRod Excel Programming 7 May 5th 05 12:20 AM
OnTime event not firing in Workbook_Open event procedure GingerTommy Excel Programming 0 September 24th 03 03:18 PM


All times are GMT +1. The time now is 05:50 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"