我有以下代码:
com_instance = Dispatch("Excel.Application") # USING WIN32COM
com_instance.Visible = True
com_instance.DisplayAlerts = False
(file_path, file_name) = os.path.split(script_file)
objworkbook = com_instance.Workbooks.Open(script_file)
xlmodule = objworkbook.VBProject.VBComponents.Add(1)
xlmodule.CodeModule.AddFromString(strcode.strip())
aux = "'"+ file_name + "'" + '!Module1.ExTracking'
com_instance.Application.Run(aux)
objworkbook.SaveAs(os.path.join(conv_scripts_dir, file_name))
com_instance.Quit()
但我得到了这个错误:
result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)
com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Excel', 'Cannot run the macro "\'Tracking NS 29Ene20.xlsx\'!Module1.ExTracking". The macro may not be available in this workbook or all macros may be disabled.", u'xlmain11.chm', 0, -2146827284), None)
我不知道Python为什么在文件名中添加这些“\”,可能是因为这个原因
请帮帮我。谢谢
目前没有回答
相关问题 更多 >
编程相关推荐