I have an Excel file that is multilingual.
I created code that fires when the workbook is opened (Initialize Sub).
It figures out the current user's local settings and language and prepares the workbook accordingly. It changes various cell values to the proper language, sets up button captions, fills in comboboxes with the proper strings and so on.
Initial setup makes the file "not saved". So when somebody opens the file and tries to close it immediately, the prompt shows up, that changes have been made and if they want to save them.
I want to avoid that, so after the initialization I tried ThisWorkbook.Saved = True
, to prevent the save prompt (see the code example). It doesn't work.
Here is my code:
Private Sub Workbook_Open()
Call Initialize
ThisWorkbook.Saved = True
End Sub
The only explanation is that something must happen after the Workbook_Open event finishes, that changes the workbook. I suspected that some formulas might be recalculating due to the changes, so I tried recalculating every sheet as part of the Initialize Sub.
I tried saving the file as well:
Private Sub Workbook_Open()
Call Initialize
ThisWorkbook.Save
ThisWorkbook.Saved = True
End Sub
It kind of worked. The prompt to save didn't display. But since there are a lot of changes during the initialization, saving takes a while and makes the file very "laggy" when opened. Also it makes the file stall when closing. I mean, when I manually save the file and then close it, it closes immediately. When I put the ThisWorkbook.Save
into the Workbook_Open event, and I open the file and then try to immediately close the file, I don't get the prompt (which is good), but it takes 10 to 15 seconds to close.
I am baffled by the behaviour in these two scenarios because when I just use:
ThisWorkbook.Saved = True
I get the prompt, which means that something must have happened that turned it to "false".
But when I use both:
ThisWorkbook.Save
ThisWorkbook.Saved = True
I don't get the prompt, which means that the "thing" that turned it to false in the first scenario doesn't happen.