Excel-win32com的宏操作

import win32com.client
xl =win32com.client.Dispatch("Excel.Application") #实例化Excel应用程序
wb =xl.Workbooks.Open(r'C:\Users\Desktop\test1.xlsm')
xl.Application.Run('test1.xlsm!模块1.getTime2("现在时刻")')
wb.Save()
xl.Application.Quit()

 宏指令:

Sub getTime()
 
     Sheet1.Cells(1, 1) = Now
 
 End Sub
 
 
 Sub getTime2(title As String)
 
     Sheet1.Cells(2, 1) = title & " : " & Now
 
 End Sub
 
 Function getTime3(title As String) As String
 
     getTime3 = title & " : " & Now
 
 End Function

 

posted @ 2023-05-15 17:36  有翅膀的大象  阅读(33)  评论(0编辑  收藏  举报