It looks like the error is occurring when the workbook is trying to close. This could be due to the fact that the workbook is still refreshing the data sources or pivot tables when the code attempts to close it. To fix this issue, try adding a delay before closing the workbook to give it time to fully refresh the data. You can do this by using the "Application.Wait" function, which will pause the code for a specified amount of time before continuing.
For example, you can add the following line before closing the workbook:
Application.Wait (Now + TimeValue("00:00:05")) 'Wait 5 seconds before closing
This will give the workbook 5 seconds to finish refreshing before closing, which should prevent the error from occurring. You can adjust the amount of time to wait as needed.