9tanstaafl9
Well-known Member
- Joined
- Mar 23, 2008
- Messages
- 535
Many years ago, I found this wonderful code on mrexcel.com that let me update all the query tables just by changing the connection string. A few Excel versions later, my code is no longer working for all the queries. It works with all the tables created in older versions of Excel, but not the Excel 2013 query tables that have that blue striped look to them.
My tables are all Visual FoxPro tables. And yes I know that is archaic, but I have to use that driver to connect to the data I need.
When I look under Data / Connections, the OLD tables have two semicolons before SourceDB, and the new tables have only one. Other than that I can't see any difference in the connection strings within Excel.
When answering, please bear in mind that I am ok with VBA, but know next to nothing about ODBC/SQL etc.
Code:
Sub ChangeDatabasePathManually()
'changes all queries in workbook
Const strPath As String = "C:\MB7\Sample Company"
Dim qt As QueryTable
Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
For Each qt In wks.QueryTables
With qt
.Connection = Join$(Array( _
"ODBC;DSN=Visual FoxPro Tables;UID=;;SourceDB=", _
strPath, _
";SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;Null=Yes;Deleted=Yes;" _
), vbNullString)
End With
Next qt
Next wks
Set qt = Nothing
Set wks = Nothing
End Sub
My tables are all Visual FoxPro tables. And yes I know that is archaic, but I have to use that driver to connect to the data I need.
When I look under Data / Connections, the OLD tables have two semicolons before SourceDB, and the new tables have only one. Other than that I can't see any difference in the connection strings within Excel.
When answering, please bear in mind that I am ok with VBA, but know next to nothing about ODBC/SQL etc.