Why doesnt my VBA script work with Python and foreward the "1" correctly?

Viewed 36

This is my first question, so please correct me if it is lacking any relevant details.

For a current Project at my university, we are trying to send a "1" to a python scrip via VBA. For some reasons, the python script is not execution the operation with the "1"

VBA script:


Dim objShell As Object
Dim PythonExe, PythonScript As String

    Set objShell = VBA.CreateObject("Wscript.Shell")

    PythonExe = """C:\Users\sralb\anaconda3\python.exe"""
    PythonScript = "C:\Users\sralb\OneDrive - Hochschule Furtwangen\Desktop\1.py 1"

    objShell.Run PythonExe & PythonScript

End Sub

Python script:

import serial
import time
import sys

arduino = serial.Serial(port='COM6', baudrate=9600, timeout=1)

def write(x):
    arduino.write(bytes(x, 'utf-8'))
    time.sleep(0)
for eachArg in sys.argv:
#   print(type(eachArg))
    print(eachArg)
if __name__ == "__main__":
    write('1')
    arduino.close()

Thank you in advance

1 Answers

The variable PythonScript has spaces, and so needs to be quoted like PythonExe (do not include the "1" in the quoted part though)

So:

PythonScript = """C:\Users\sralb\OneDrive - Hochschule Furtwangen\Desktop\1.py"" 1"
Related