I am running a script that creates a workbook, write some data into it then saves it.
At the end of my script I have:
workbook.SaveAs('tempfile.xlsx')
But what is happening is that it keeps saving to some obscure directory, where earlier today I downloaded an excel file from a sharepoint site. So I tried:
import os
os.chdir('C:/mydir')
Then I run the script and it still saves to the obscure directory. I type in os.getcwd() into IDLE prompt and it returns 'C:/mydir.'
Cannot figure out how to get this saving properly. When I try:
workbook.SaveAs('C:/mydir/tempfile.xlsx')
I get an error:
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Office Excel', "Microsoft Office Excel cannot access the file 'C:\\weird dir\\//mydir/FC424E40'. There are several possible reasons:\n\n• The file name or path does not exist.\n• The file is being used by another program.\n• The workbook you are trying to save has the same name as a currently open workbook.", 'C:\\Program Files (x86)\\Microsoft Office\\Office12\\1033\\XLMAIN11.CHM', 0, -2146827284), None)
I know this is probably a simple fix but I can't figure it out. Any ideas?