I am trying to run a python script I inherited. I'm not a programmer, but know enough to understand. The problem is that this script works perfectly in my older machine, but still 64bit machine with Office 365 - Excel.
I keep getting the error when I migrated to a new machine. I need some assistance how to fix it so it works on the new machine. Below is the error and part of the script where it is failing.
PermissionError Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_16060/1139512431.py in 121 122 #Delete unneeded xlsx file --> 123 os.remove("C:\MarketCentre Deals Report\Data Files\MarketCentreDealsReport_West_"+datetime.datetime.now().strftime("%m.%d.%Y")+".xlsx") 124 125 ##########################################################################################################################
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\MarketCentre Deals Report\Data Files\MarketCentreDealsReport_West_03.07.2022.xlsx'
Code where it is erroring:
#Resave final file as xlsb to reduce file size
excel = win32com.client.Dispatch("Excel.Application")
doc = excel.Workbooks.Open("C:\\MarketCentre Deals Report\\Data Files\\MarketCentreDealsReport_East_"+datetime.datetime.now().strftime("%m.%d.%Y")+".xlsx")
doc.SaveAs( "C:\\MarketCentre Deals Report\\Data Files\\MarketCentreDealsReport_East_"+datetime.datetime.now().strftime("%m.%d.%Y")+".xlsb", 50 )