Active Member
November 13, 2024
I have a macro that refreshes a data query that gets information about the files in a specific folder. In the properties settings for the query all the refresh options are off.
The macro (GetNewDocuments) is run automatically when the workbook is opened. This is done from Auto_Open. Auto_Open tells the GetNewDocuments macro to save the workbook when the refresh is finished.
I know that the workbook has been saved by checking the last modified time for the workbook.
However when I close the workbook without having made any additional changes Excel asks if a save should be done.
I added Application.CalculateFull, Application.CalculateAsyncQueriesDone and the DoEvents loop waiting on xlDone to see if would help. None of these changes made any difference.
If I change the UpdateDocuments macro to pass True instead of False the workbook is saved and I can close it without Excel asking to save it again. The problem only occurs when GetNewDocuments is called from Do_Open.
Anyone have an idea what I am missing?
Source for macros:
Sub GetNewDocuments(DoSave As Boolean) ' ' UpdateDocuments Macro ' Get new documents that have been added to the source folder ' ActiveWorkbook.Connections("Query - FolderFilesList").OLEDBConnection.BackgroundQuery = False ActiveWorkbook.Connections("Query - FolderFilesList").Refresh Application.CommandBars("Queries and Connections").Visible = False Sheets(1).Select Cells(1, 1).Select Application.CalculateFull Application.CalculateUntilAsyncQueriesDone Do While Application.CalculationState <> xlDone DoEvents Loop If DoSave Then ActiveWorkbook.Save End If End Sub Sub UpdateDocuments() ' Add new documents when a button linked to this macro is clicked, workbook is not saved Call GetNewDocuments(False) End Sub Sub Auto_Open() ' Add new documents when spreadsheet is opened, workbook is saved Call GetNewDocuments(True) End Sub
Trusted Members
October 17, 2018
The moment a calculate ful or whatever is done any formula is updated too or refreshed, this triggers the flag that there has been a change made to the workbook so when you close the workbook not consciously made any changes it still 'thinks' it's changed.
You will have to for example add an extra check in a before close event to check if any real changes have actually been made.
Hope my explanation makes sense.
Just post if you need help
VIP
Trusted Members
December 7, 2016
VIP
Trusted Members
December 7, 2016
Trusted Members
October 17, 2018
Hi Mike, Anders,
I'm now doubting if there isn't some setting MicroSoft has spontaneously added when closing Excel.
I have a file which I haven't used in the past two months that worked perfectly and never asked me to confirm to save it again.
My routine (macro) did this and set a global parameter End_Session to True when I pressed the buton asking to end the session.
The macro handles all the actions like resetting the file and then prompt me if I want to quit the session and if so if I want to save the file.
When all is Yes this is done and the Global End_Session is set to TRUE
And an application.Quit is executed.
When Workbook_BeforeClose is triggered and End_Seeion = true it sets Thisworkbook.Saved = true so it should NOT ask me to save it again, but it does.
In the screen shot I have attached you can see that it's mentioning a backup in the Cloud which I have not activated but ... where does this como from, so I can understand Mike's worries and question completely
I wonder if others are having the same issues
By the way, if I click 'Don't Save' the file last saved date is a few seconds before when I confirmed to end and save the session, so it has no influence on the saved data, but it is very confusing to say the least.
1 Guest(s)