FileNotFoundError when trying to run a python script accessing PDFs through macro - macro using different directory

Viewed 28

When I run the program on the command line it works, when I press the button on VBA that is connected to the macro calling the python file I get this error:

    File "c:\users\amscha\desktop\development tools\file.py", line 85, in get_drawing_set_data
    fp = open(drawing_set, 'rb')

    FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\amscha\\Documents\\P Test.pdf'

Error is saying the path is to the documents folder, but I used the below code to assign the full path to the pdf:

    drawing_set = "example.pdf"
    cwd = Path.cwd()
    drawing_set = f"{cwd}\\{drawing_set}"

then passing drawing_set into the function where it is being opened. How to I make VBA know to use the same directory as the python file is stored in?

0 Answers
Related