从Python打开或运行VBA宏
我正在尝试从Python运行VBA宏从Python打开或运行VBA宏,python,excel,vba,Python,Excel,Vba,我正在尝试从Python运行VBA宏 import win32com.client as wincl def runMacro(): if os.path.exists("C:\\Users\\care\\macro_conversion.xlsm"): excel_macro = wincl.DispatchEx("Excel.application") excel_path = os.path.expanduser("C:\\Users\\car
import win32com.client as wincl
def runMacro():
if os.path.exists("C:\\Users\\care\\macro_conversion.xlsm"):
excel_macro = wincl.DispatchEx("Excel.application")
excel_path = os.path.expanduser("C:\\Users\\care\\macro_conversion.xlsm")
workbook = excel_macro.Workbooks.Open(Filename = excel_path, ReadOnly =1)
#excel_macro.Application.Run\
# ("ThisWorkbook.Template2G")
#Save the results in case you have generated data
# workbook.Save()
#excel_macro.Application.Quit()
del excel_macro
runMacro()
它没有给出错误,但什么也不做
我附上了密码。我对运行宏的部分进行了注释,因为我甚至无法从Python打开Excel文件
import win32com.client as wincl
def runMacro():
if os.path.exists("C:\\Users\\care\\macro_conversion.xlsm"):
excel_macro = wincl.DispatchEx("Excel.application")
excel_path = os.path.expanduser("C:\\Users\\care\\macro_conversion.xlsm")
workbook = excel_macro.Workbooks.Open(Filename = excel_path, ReadOnly =1)
#excel_macro.Application.Run\
# ("ThisWorkbook.Template2G")
#Save the results in case you have generated data
# workbook.Save()
#excel_macro.Application.Quit()
del excel_macro
runMacro()