I have an Excel file that has a bunch of formulas in them. It takes time for the formulas to properly load (~1-2 mins), so I'm trying to add some delay between opening the file and saving the loaded file. After this is done, I'm hoping to save a copy of the fully loaded Excel file as a new CSV with a different name, so that I have both the fully loaded Excel file and new CSV file.
To be clear, I'm trying to do the following tasks in this order:
- Open the Excel file
- Add some delay (~1-2 mins long)
- Save the fully loaded Excel file
- Save a copy of the fully loaded Excel file as a CSV with a different name
I've managed to do Steps 1 and 3 as seen below, but am having trouble with Steps 2 and 4. I've noticed Step 2 is quite important, since the way my code is written right now does not allow for enough time for the formulas to load, leading to an incompletely-loaded file.
What is the best way to do Steps 2 and 4, i.e., add delay and then save the full file as a CSV?
import win32com.client as win32
excel = win32.gencache.EnsureDispatch('Excel.Application')
#opens file denoted by PATH
workbook = excel.Workbooks.Open(PATH)
#saves file
workbook.Save()
#closes and quits Excel
workbook.Close()
excel.Quit()
Note this code is based on this post.