I am running a code as below in python to open an excel and run a macro. Basically my python script is sitting in
C:\Users\adrlee\Desktop\Python files\Automation
and my excel VBA file (Automation.xlsb) is sitting in
C:\Users\adrlee\Desktop\Python files\Automation\Powerpoint
I am running this code
fileDir = os.path.dirname(os.path.realpath('__file__'));
filename = os.path.join(fileDir, '../Powerpoint/Automation.xlsb')
filename = os.path.abspath(os.path.realpath(filename))
print(filename);
if os.path.exists("Powerpoint/Automation.xlsb"):
xl=win32com.client.Dispatch("Excel.Application")
xl.Workbooks.Open(filename)
xl.Application.Quit() # Comment this out if your excel script closes
del xl
print("Powerpoint generated");
but i am getting error
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Excel', "Sorry, we couldn't find C:\\Users\\adrlee\\Desktop\\Python files\\Powerpoint\\Automation.xlsb. Is it possible it was moved, renamed or deleted?", 'xlmain11.chm', 0, -2146827284), None)
What am i doing wrong
C:\Users\adrlee\Desktop\Python files\Automationand the Excel file isC:\Users\adrlee\Desktop\Python files\Automation\Powerpoint\Automation.xlsbwouldn't you want'./Powerpoint/Automation.xlsb'instead of'../Powerpoint/Automation.xlsb'?Open, but you are actually passing the absolute path. I think you just need to specify the path relative to the current path instead of to the current path's parent - i.e..instead of..