Forum: Ruby ruby as excel vba event handler replacement using win32ole?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
4f86dba83a7b1b127263bb3fdd0b09e7?d=identicon&s=25 Ammon Christiansen (ammonc)
on 2006-01-12 18:16
(Received via mailing list)
I've seen Ruby used as a script to save all Word doc files as rtf
instead.
Can ruby be used interactively to process events that would usually be
handled in VBA in Excel for example?
E97181961afa48102e3a28daab69b904?d=identicon&s=25 Masaki Suketa (Guest)
on 2006-01-16 12:47
(Received via mailing list)
Hello,
In message "ruby as excel vba event handler replacement using win32ole?"
    on 06/01/13, Ammon Christiansen <ammon.christiansen@gmail.com>
writes:

> Can ruby be used interactively to process events that would usually be
> handled in VBA in Excel for example?

Does WIN32OLE_EVENT class help you?

require 'win32ole'

def sheet_changed(arg1, arg2)
  p arg1.value
end

excel = WIN32OLE.new("Excel.Application")
excel.visible = true
book = excel.workbooks.Add
ev = WIN32OLE_EVENT.new(book, 'WorkbookEvents')
ev.on_event('SheetChange'){|arg1, arg2|
  sheet_changed(arg1, arg2)
}

book.Worksheets(1).Range("A1").value = 100
book.Worksheets(1).Range("A2").value = 200
book.Worksheets(1).Range("B1").value = 300
4f86dba83a7b1b127263bb3fdd0b09e7?d=identicon&s=25 Ammon Christiansen (ammonc)
on 2006-01-17 19:07
(Received via mailing list)
Thanks, I'll try that!  That is the kind of thing I was looking for -
event
handling in Ruby.
This topic is locked and can not be replied to.