Skip to content

Instantly share code, notes, and snippets.

@nobrinskii
Created April 3, 2012 11:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nobrinskii/2291333 to your computer and use it in GitHub Desktop.
Save nobrinskii/2291333 to your computer and use it in GitHub Desktop.
エクセルVBAファイルにファイルパスを投げるドロップレット
#!ruby -Ks
require 'win32ole'
wsh = WIN32OLE.new('WScript.Shell')
#
# 事前設定
#
MACRO_FILE = "MacroFileName"
MACRO_NAME = "MacroName"
#--
#
#以下、処理部分
#
#++
excel = WIN32OLE.new('Excel.Application')
excel.visible = false
macro_book = nil
macro_file_path = File::dirname(__FILE__) + "\\" + MACRO_FILE
message = ""
begin
if FileTest::exist?(macro_file_path) then
macro_book = excel.Workbooks.Open(macro_file_path)
excel.run(MACRO_NAME, ARGV)
macro_book.close('SaveChanges' => false)
message = "完了しました。"
else
message = "マクロを含んだファイルが見つかりませんでした。"
end
rescue => e
puts e.message
puts e.backtrace
message = "エラーで中断しました。"
ensure
excel.visible = true
excel.quit
end
wsh.popup(message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment