pythonexcelmicrosoft365

Using Python in Excel doesnt show correct working directory


i want to test Python integrated in Excel a bit and i wrote the following sourcecode that should change the current working directory into a specific one. But it doesnt work.

If i check my CWD it shows me \mnt\file_upload and i want to change to "C:\Users\User1\Desktop" but i get the following error

Fehler: [Errno 2] No such file or directory: 'C:\Users\User1\Desktop'

My Code is the following

import os
from pathlib import Path

try:
    neuerpfad = Path(r'C:\Users\User1\Desktop')
    os.chdir(neuerpfad)
    print("Aktueller Pfad: ", Path.cwd())
except FileNotFoundError as e:
    print(f"Fehler: {e}")

If i try it for example in PyCharm it works fine.

Is it possible to do this operation in Excel?

Thanks a lot.

I tried to search a solution using Google and other Search Engines but i can figure it out.


Solution

  • The Microsoft Documentation mentioned from Flow says

    The Python code does not have access to your computer, devices, or account. The Python code does not have network access.

    We can close this Question.