首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在excel VBA中执行Python脚本

如何在excel VBA中执行Python脚本
EN

Stack Overflow用户
提问于 2019-06-13 09:05:01
回答 1查看 422关注 0票数 0

我正在尝试通过Excel VBA运行Python脚本

我尝试了以下代码,但什么也没有发生:

以下是VBA代码:

代码语言:javascript
复制
RetVal = Shell("C:\Program Files\Python37\python.exe C:\Users\kailung\Desktop\kai\VBA\june_Longchen\test\VBA.py")

我的python脚本只是重命名文件夹中的文件(我已经在Python IDLE中对其进行了测试,它很好):

代码语言:javascript
复制
import os, sys

dir_path = os.path.dirname(os.path.realpath(__file__))

# Open a file
dirs = os.listdir(dir_path)

i=1

# This would print all the files and directories
for file in dirs:
   if file!='VBA.xlsm' and file!='VBA.py' and file!='~$VBA.xlsm':
        print(file) #print all the files
        i=str(i) #change to string for file name
        i=i + '.xls' #add extension
        os.rename(file,i) #rename the file
        size=len(i) 
        i=i[0:size-4] #remove the extension
        i=int(i) #change back to numerical
        i=i+1 #new numerical name
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-13 09:16:41

使用pyinstaller将.py文件转换为.exe文件,然后直接从.exe代码运行VBA程序。

How to use pyinstaller?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56572106

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档