tag:blogger.com,1999:blog-284600789737488130.post6211647160310969859..comments2024-02-07T02:22:20.642-05:00Comments on Ruby on Windows: Automating Excel with Ruby: The Workbook ObjectDavid Mullethttp://www.blogger.com/profile/05597492688893461137noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-284600789737488130.post-608724198498733132007-09-07T19:19:00.000-05:002007-09-07T19:19:00.000-05:00@Brian:That's a good point. I usually do use singl...@Brian:<BR/><BR/>That's a good point. I usually do use single-quotes, to allow me to use the standard backslash separator ('\'). When using double-quotes, you'll need to either switch to the forward slash ("/") or escape the backslash with another backslash ("\\").<BR/><BR/>DavidDavid Mullethttps://www.blogger.com/profile/05597492688893461137noreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-11708625560388266702007-08-30T15:52:00.000-05:002007-08-30T15:52:00.000-05:00One caveat of the following line:workbook.SaveAs('...One caveat of the following line:<BR/>workbook.SaveAs('c:\temp\YourWorkbook.xls')<BR/>Notice that you use single quotes so that you can use the \ between directories. If, however you need variable substitution in your filename, you <B>must</B> use / (unix-like) between your directory<BR/>entries.(i.eworkbook.SaveAs("c:/temp/YourWorkbook#{Date.today.to_s}.xls")<BR/>I spent quite a bit of time with this, thinking that I spelled the<BR/>name SaveAS wrong. The error (at least in my case) was method_missing from Win32::OLE, which was very misleading.Unknownhttps://www.blogger.com/profile/18333329199414850192noreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-61680117288847962592007-05-21T20:22:00.000-05:002007-05-21T20:22:00.000-05:00"What about closing without saving changes?"workbo..."What about closing without saving changes?"<BR/><BR/>workbook.Close(false)<BR/><BR/>Also, you can turn off alerts by setting the Application object's DisplayAlerts property...<BR/><BR/>excel.DisplayAlerts = false<BR/><BR/>DavidDavid Mullethttps://www.blogger.com/profile/05597492688893461137noreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-59974493553137342592007-05-21T19:30:00.000-05:002007-05-21T19:30:00.000-05:00What about closing without saving changes? Any wa...What about closing without saving changes? Any way to do that without it popping up the prompt to save?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-68062884898273212342007-04-04T13:59:00.000-05:002007-04-04T13:59:00.000-05:00My google searching has also returned no method th...My google searching has also returned no method that does this. There is an .Index method on most objects, but not one for Workbook. I think your solution would be best.Walkerhttps://www.blogger.com/profile/14152234200831316723noreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-23016141006790005872007-04-04T08:01:00.000-05:002007-04-04T08:01:00.000-05:00walker-I'm not aware of such a method/property. Yo...walker-<BR/><BR/>I'm not aware of such a method/property. You could, however, iterate over the excel.Workbooks collection and compare the Workbook.Name value. For example:<BR/><BR/>def get_index_from_name(wb_name)<BR/> i = 0<BR/> for workbook in excel.Workbooks<BR/> i = i + 1<BR/> if workbook.Name == [value]<BR/> return i<BR/> end<BR/> end<BR/>end<BR/><BR/>index = get_index_from_name('workbook.xls')<BR/><BR/>There's probably more elegant code to do this, but you get the idea.<BR/><BR/>Keep in mind that there could be hidden workbooks in the collection, such as the PERSONAL.XLS workbook that is normally used to store macros.<BR/><BR/>-DavidDavid Mullethttps://www.blogger.com/profile/05597492688893461137noreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-67861936396363204072007-04-02T10:55:00.000-05:002007-04-02T10:55:00.000-05:00Is there a method that returns the index of a give...Is there a method that returns the index of a given workbook?Walkerhttps://www.blogger.com/profile/14152234200831316723noreply@blogger.com