TransWikia.com

Python script runs from command line, stopped working from Excel Shell

Stack Overflow Asked on December 16, 2021

I have a Python script that’s been running successfully when executed from Excel on a remote server. I recently did some testing from my local PC, updating the Python script and testing via remote desktop.
Since then, when on the remote desktop the Python scripts work when executed from the command line, but stopped working when the same command is executed from within Excel. Example of code:

'Get file from Gmail using a Python script
vPytnonDir = "C:ProjectsPython"
ChDir vPytnonDir  'Directory where python script resides
Dim wShell As Object
Set wShell = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
wShell.Run "cmd.exe /S /C python GetGmail.py", windowStyle, waitOnReturn

When I run "cmd.exe /S /C python GetGmail.py" in a command window (in the Python directory) the command works.
I’ve refreshed the credentials.json and token.json to have the same user access to Gmail.
I’ve put a pause in the Python script, and the execute window just flashes, apparently the script doesn’t get to the pause.
I’ve created a stand-alone Excel with just the sample code – AND THAT WORKS!
This is driving me batty (can’t say crazy, already there) – Any help would be appreciated.

THIS HAS BEEN RESOLVED!
When I had done testing from my local PC, I had connected to the server via the "E" drive, and somehow that had reset the default drive for Excel. The ChDir command in the code wasn’t working at all, I had to run ChDrive("C") to get things back to normal.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP