EDIT: This is the same question but I rewrote it, so it is more legible.
I already tried this post: How to call python script on excel vba?
And this post: Run and execute a python script from VBA
And this post: How can I call python program from VBA?
But none of the answers works for me and I have no idea what I'm doing wrong. Problem 1: I want to run a pythonscript from VBA excel. excel file doesn't have a home place (can be on any desktop). the code I (want to) use:
Dim Ret_Val
Ret_Val = Shell("C:\python27\python.exe \\10.31.13.22\SharedDocs\3 - Technical\13 - Reports & Templates\13 - Description\DescriptionToDatabase.py")
The pythonfile has always the same path on the server. I cannot see wat is wrong here? All I get is a black python screen.
In the python file I call the workbook and the correct sheet:
book = xlrd.open_workbook("//10.31.13.22/SharedDocs/3 - Technical/1 - Projects/0 - Internal/RPA 138 - Engineering software/testchipdescription/upload to database/testchipdescription-template-10-11.xltm")
sheet = book.sheet_by_name("Database")
At the moment the excel workbook path is hardcoded in python. This will bring me back to problem 2: Can I pass the name and path of the excel workbook somehow to my pythonscript?
EDIT:
I tried the shell()code in command prompt. The same as in VBA:
"C:\python27\python.exe \\10.31.13.22\SharedDocs\3 - Technical\13 - Reports & Templates\13 - Description\DescriptionToDatabase.py"
It doesn't work. 'The system cannot find the path specified'.
I tried this one:
C:\python27\python.exe "\\10.31.13.22\SharedDocs\3 - Technical\13 - Reports & Templates\13 - Description\DescriptionToDatabase.py"
And it works! So the cmd needs "" to handle the spaces in the path. But I can't add them in VBA because I cannot place 2 "" otherwise it errors.