python运行excel的VBA代码

2022/7/13 14:21:35

本文主要是介绍python运行excel的VBA代码,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

import os, os.path
import win32com.client
    
if os.path.exists("ceshi.xlsm"):
    xl=win32com.client.Dispatch("Excel.Application")
    wb = xl.Workbooks.Open(os.path.abspath("ceshi.xlsm"), ReadOnly=1) #打开excel文件,只读模式
    xl.Application.Run("ceshi.xlsm!Module1.ceshi") #运行VBA代码
    wb.Close(False) #close the work sheet object rather than quitting excel
    del wb
    del xl

  python运行excel的VBA代码;非常简单。



这篇关于python运行excel的VBA代码的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程