我希望错误与您正在调用的宏有关,请尝试以下代码:
码
import os, os.pathimport win32com.clientif os.path.exists("excelsheet.xlsm"): xl=win32com.client.Dispatch("Excel.Application") xl.Workbooks.Open(os.path.abspath("excelsheet.xlsm"), Readonly=1) xl.Application.Run("excelsheet.xlsm!modulename.macroname")## xl.Application.Save() # if you want to save then uncomment this line and change delete the ", Readonly=1" part from the open function. xl.Application.Quit() # Comment this out if your excel script closes del xl


