1.录制宏保存到个人宏工作簿
2.隐藏个人宏工作簿
import win32com.client
def usePersonalVBA(VBA):
xlApp = win32com.client.DispatchEx("Excel.Application")
xlApp.Visible = False
xlApp.DisplayAlerts = 0
xlBook = xlApp.Workbooks.Open(file_path,True)
xlApp.Workbooks.Open(macro_path,True) #打开个人宏工作簿
xlBook.Application.Run(VBA) #运行宏
xlApp.ExecuteExcel4Macro(VBA)
xlBook.Close(True)
xlApp.quit()
file_path = r"C:\Users\Administrator\Desktop\吗.xlsx"
macro_path=r'C:\Users\Administrator\AppData\Roaming\Microsoft\Excel\XLSTART\PERSONAL.XLSB'
usePersonalVBA(r'PERSONAL.XLSB!清除格式')
网友评论