def read_activex():
global xlsm_path, xlsm_sheet
xlsm_path = r'D:\TEST.xlsm'
xlsm_sheet = 'pat_history'
exl = win32com.client.gencache.EnsureDispatch('Excel.Application')
exl.EnableEvents = False
exl.DisplayAlerts = False
wb = exl.Workbooks.Open(xlsm_path)
ws = wb.Worksheets(xlsm_sheet)
# print(ws)
# print('Shape count: %s' % len(ws.Shapes))
for shape in ws.Shapes:
print('ActiveX Name:', str(shape.Name), 'Type:', shape.Type, 'Text"', shape.AlternativeText)
你试试下面代码
import win32com.client
xls = win32com.client.Dispatch("Excel.Application")
xls.Workbooks.Open("宏代码所在excel全路径")
xls.Application.Run("宏名称")
xls.Application.Quit()