Open Excel code to a Plug-in.
- 
 ` #UI.menu("PlugIns").add_item("Open Excel") { Open_Excel } #def Open_Excel 
 require 'win32ole'
 excel = WIN32OLE.new('Excel.Application')
 excel.Visible = true
 number_of_sheets = excel.SheetsInNewWorkbook
 excel.SheetsInNewWorkbook = 1
 workbook = excel.Workbooks.Add
 excel.SheetsInNewWorkbook = number_of_sheets
 workbook.SaveAs('C:\TestFolder\YourWorkbook2.xlsx')workbook = excel.Workbooks.Open('C:\Users\Dave\AppData\Roaming\SketchUp\SketchUp 2014\SketchUp\Plugins\MyWorkbook.xlsx') 
 #end`Hello,still new to Ruby 
 This works when I run it through the ruby console, but I can't figure out the way to make it a Plug-in. I have added "#" to the lines that should make it a Plug-in.When I run the code throught the console, it creates a new workbook, saves it, then opens a different workbook. When I remove the "#" save the code and open Sketch-up. 
 "Open excel" shows in the plug-in menu, when I click it though nothing happens.Thanks in advanced. 
- 
 This approach will work. 
 The command [as used in the Plugins menu] isOpen_Excel.new()require('sketchup.rb') module Open_Excel UI.menu("Plugins").add_item("Open Excel") { self.new() } unless file_loaded?(__FILE__) file_loaded(__FILE__) def self.new() require('win32ole') excel = WIN32OLE.new('Excel.Application') excel.Visible = true number_of_sheets = excel.SheetsInNewWorkbook excel.SheetsInNewWorkbook = 1 workbook = excel.Workbooks.Add excel.SheetsInNewWorkbook = number_of_sheets workbook.SaveAs('C;\TestFolder\Test.xls') ### Do your stuff... #workbook = excel.Workbooks.Open('C;\Users\Dave\AppData\Roaming\SketchUp\SketchUp 2014\SketchUp\Plugins\MyWorkbook.xls') ### ### Tidy exit... workbook.Close() excel.Quit() WIN32OLE.ole_free(excel) excel.ole_free workbook=nil excel=nil GC.start end end
- 
 Thank You Very much. 
Advertisement

 
                             
                             
                             
                             
                             
                             
                            