[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

ruby as excel vba event handler replacement using win32ole?

Ammon Christiansen

1/12/2006 5:14:00 PM

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?
3 Answers

Masaki Suketa

1/16/2006 11:46:00 AM

0

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




Ammon Christiansen

1/17/2006 5:31:00 PM

0

Thanks, I'll try that! That is the kind of thing I was looking for - event
handling in Ruby.

On 1/16/06, Masaki Suketa <masaki.suketa@nifty.ne.jp> wrote:
>
> 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
>
>
>
>

Chris McMahon

1/17/2006 10:47:00 PM

0

Stuff in here might help you:

http://www.rubygarden.org/ruby?Scri...