我正在尝试通过Excel VBA运行Python脚本
我尝试了以下代码,但什么也没有发生:
以下是VBA代码:
RetVal = Shell("C:\Program Files\Python37\python.exe C:\Users\kailung\Desktop\kai\VBA\june_Longchen\test\VBA.py")我的python脚本只是重命名文件夹中的文件(我已经在Python IDLE中对其进行了测试,它很好):
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发布于 2019-06-13 09:16:41
使用pyinstaller将.py文件转换为.exe文件,然后直接从.exe代码运行VBA程序。
https://stackoverflow.com/questions/56572106
复制相似问题