I was testing calling the StockHistory
function from VBA (available only in Microsoft 365 versions of Excel) and I noticed that afterwards Excel started complaining about the workbook being corrupted and completely failed at being able to save the workbook once more. I initially thought the issue was caused by the updating of data in the workbook I was doing but after having removed all code apart the call to the StockHistory function I realized that it is the call itself that is destabilizing Excel. Below the stripped-down function to reproduce the problem. Force multiple executions (at least two) of the function by clicking CRTL+ALT+F9 and then try to save the workbook.
Public Function GetData(ticker As String) As String
Dim data As Variant
data = Application.WorksheetFunction.StockHistory(ticker, Date - 10, Date, 0, 0, 1)
GetData = ticker
End Function
My Excel should be the latest available via M365 (Excel for Microsoft 365 MSO – Version 2406 Build 16.0.17726.20078 – 64-bit).