sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🚨 Skimp | 25% Off until March 30 Buy Now

    Open Excel code to a Plug-in.

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 509 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D Offline
      davesexcel
      last edited by

      ` #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.

      1 Reply Last reply Reply Quote 0
      • TIGT Online
        TIG Moderator
        last edited by

        This approach will work.
        The command [as used in the Plugins menu] is Open_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
        
        

        TIG

        1 Reply Last reply Reply Quote 0
        • D Offline
          davesexcel
          last edited by

          Thank You Very much.

          1 Reply Last reply Reply Quote 0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better πŸ’—

          Register Login
          • 1 / 1
          • First post
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement