Я пытаюсь запустить скрипт Python через Excel VBA
Я пробовал следующий код, но ничего не произошло:
Вот код 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