Created
April 3, 2012 11:53
-
-
Save nobrinskii/2291333 to your computer and use it in GitHub Desktop.
エクセルVBAファイルにファイルパスを投げるドロップレット
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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