2013-07-17 52 views
1

我在excel中創建了一個宏,其快捷鍵爲CTRL + l。我想運行這個宏使用python3.3從Python執行Excel宏

有人可以幫我嗎?這是我管理至今:

import win32com.client as win32 
xl = win32.gencache.EnsureDispatch('Excel.Application') 
xl.Visible = 1 
xl.Workbooks.Open("C:\Python33\mac.xlsm") 

回答

0

我從來沒有這樣做與EnsureDispatch,但這裏是你如何與調度

from win32com.client import Dispatch 

xlApp = Dispatch('Excel.Application') 

result = xlApp.Run("<macro name here>",<the macro variables go here -seperate each one with a comma>) 
# for example: 
#result = xlApp.Run("myMacro", "foo","bar") 

#and make sure you close the xl 
xlApp.Quit() 

哦做到這一點,我ASLO的蟒蛇2.7(但我懷疑這將是重要的,因爲依賴項是win32)

0

我試圖爲Python 3.3應用一個示例。只需添加應用程序即可獲得結果!

from win32com.client import Dispatch 
xlApp = Dispatch('Excel.Application') 
xlApp.Workbooks.Open("C:\Python33\mac.xlsm") 
result = xlApp.Application.Run("<macro name here>",<the macro variables go here -seperate each one with a command>)