1

I have a workbook with a multiple queries from an SQL database and wanted to get the last refreshed date/time as either a variable in VBA or written to a cell in the workbook.

I tried this code:

Cells(1,1) = ActiveWorkbook.Connections("Query - Item_Groups").ODBCConnection.RefreshDate

But I get I get an Application Defined or Object Defined error.

Any thoughts?

BigBen
  • 46,229
  • 7
  • 24
  • 40
  • 1
    Is it actually an ODBCConnection? What does `Debug.Print ActiveWorkbook.Connections("Query - Item_Groups").Type` return in the Immediate Window? – BigBen Nov 16 '21 at 18:07
  • it just gives me a "1" I tried OLEDBConnection too I cant seem to get anything that will produce a RefreshDate – Nasser Ramsis Nov 16 '21 at 20:56
  • `1` corresponds to `xlConnectionTypeOLEDB` as documented [here](https://learn.microsoft.com/en-us/office/vba/api/excel.xlconnectiontype). [This](https://stackoverflow.com/questions/53727363/oledb-connection-has-no-refresh-date) might also be useful. – BigBen Nov 16 '21 at 21:00
  • Thanks @BigBen! the solutions in that link should get me what I need! – Nasser Ramsis Nov 16 '21 at 21:09

0 Answers0