tag:blogger.com,1999:blog-284600789737488130.post51378938883300057..comments2024-02-07T02:22:20.642-05:00Comments on Ruby on Windows: Ruby & Excel: The InputBox HackDavid Mullethttp://www.blogger.com/profile/05597492688893461137noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-284600789737488130.post-82020770183019578542013-05-15T13:42:36.868-05:002013-05-15T13:42:36.868-05:00First at all, I give you an apologize... mi englis...First at all, I give you an apologize... mi english is not so good!<br /><br />What I have todo if I want a inputbox to select a range? Because en Excel I can do this:<br /><br />set rngRange = Application.Inputbox("Select data", "Sample", type:=8)<br /><br />With this rngRange is linked with the range seleccionated, but Ruby code dont work!<br /><br />Help!Luis Cervanteshttps://www.blogger.com/profile/12322056831391422762noreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-76042894789071297882010-02-25T11:14:27.272-05:002010-02-25T11:14:27.272-05:00This is a another possibility:
def inputbox( mess...This is a another possibility:<br /><br />def inputbox( message, title="Message from #{__FILE__}" )<br /> # returns nil if 'cancel' is clicked<br /> # returns a (possibly empty) string otherwise<br /> require 'win32ole' <br /> # hammer the arguments to vb-script style<br /> vb_msg = %Q| "#{message.gsub("\n",'"& vbcrlf &"')}"|<br /> vb_msg.gsub!( "\t", '"& vbtab &"' )<br /> vb_msg.gsub!( '&""&','&' )<br /> vb_title = %Q|"#{title}"|<br /> # go!<br /> sc = WIN32OLE.new( "ScriptControl" )<br /> sc.language = "VBScript"<br /> sc.eval(%Q|Inputbox(#{vb_msg}, #{vb_title})|)<br />end<br /><br />def popup(message)<br /> require 'win32ole'<br /> wsh = WIN32OLE.new('WScript.Shell')<br /> wsh.popup(message, 0, __FILE__)<br />end<br /><br />#simple use<br />res = inputbox "Your input please." <br />popup res<br /><br />#using linebreaks and tabs<br />str = "a | does not break it...\n\nOne\n\tTwo tabbed\nThree..."<br />res = inputbox( str, "demonstration | title")<br />popup %Q|When asked\n\n"#{str}"\n\nyou answered:\n#{res}| <br /><br />(code also available on http://snippets.dzone.com/posts/show/10261 .<br /><br />hth,<br />Siepsteenslagnoreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-55906523503293265002008-04-09T12:58:00.000-05:002008-04-09T12:58:00.000-05:00r = js.input(prompt) should ber = js.prompt(prompt...r = js.input(prompt) should be<BR/>r = js.prompt(prompt)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-82476612901416539242008-04-09T12:50:00.000-05:002008-04-09T12:50:00.000-05:00js.input(prompt) results in an error. unknown prop...js.input(prompt) results in an error. unknown property or method `input' (WIN32OLERuntimeError). What could be wrong?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-530044897920239832007-04-27T11:34:00.000-05:002007-04-27T11:34:00.000-05:00I say it would be better to use IE's script engine...I say it would be better to use IE's script engine (input, confirm, alerts), you get more options, and IE is guaranteed to be present on a Windows machine, whereas Excel isn't.<BR/> js = ie.document.script<BR/> js.alert(prompt)<BR/> r = js.confirm(prompt)<BR/> r = js.input(prompt)<BR/>...tremendohttps://www.blogger.com/profile/02474546066660794460noreply@blogger.com