【发布时间】:2018-11-10 09:12:17
【问题描述】:
python 的代码可以工作,但一旦运行,我仍然会从 excel 中得到一个框,询问“想要保存对工作簿的更改”我的代码中似乎缺少的是添加一些将保存工作簿的内容最后。我在工作簿中使用 RTD 函数,这可能是弹出窗口的原因。
这是我使用的python代码。
from __future__ import print_function
import unittest
import os.path
import win32com.client
class ExcelMacro(unittest.TestCase):
def test_excel_macro(self):
try:
xlApp = win32com.client.DispatchEx('Excel.Application')
xlsPath = os.path.expanduser('C:\Magic Samsung\Watch Samsung\Workbook.xlsm')
wb = xlApp.Workbooks.Open(Filename=xlsPath)
xlApp.Run('ArchiveMaster')
wb.Save()
xlApp.Quit()
print("Macro ran successfully!")
except:
print("Error found while running the excel macro!")
xlApp.Quit()
if __name__ == "__main__":
unittest.main()
【问题讨论】:
-
您是否尝试将其保存为启用宏的 ..with .xlsm 扩展名
-
是的,我已将其保存为启用宏。
-
下面的代码正在工作@Try?