LoginSignup
9
10

More than 5 years have passed since last update.

複数のExcelが起動しているときにrubyのWIN32OLEで特定のブックを操作する

Last updated at Posted at 2014-06-12

WIN32ole.connect('Excel.Application')とすると起動中のEXCELオブジェクトが取れます。

しかし、複数起動していると、一番初めに起動したEXCELしか取れず、残念な感じ。

WIN32ole.connect(ブックのファイル名)とすると、複数起動していても、特定のブックが取れます。

そのブックが開かれていない場合は新たに開きます。

require 'win32ole'

work_book = WIN32OLE.connect('C:/test.xlsx') # 絶対パスでないとダメっぽい
# WIN32ole.connect('Excel.Application')ではExcelアプリケーションのオブジェクトが返るがこれはワークブックのオブジェクトが返る。

work_book.Name #=> test.xlsx
9
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
10