Hi guys,
I have this code that has always worked for me in the past. It simply loops through all sheets looking for querytables and then re-writes the connection string. I think I initially had it done for Excel 2003 but it should also work for 2010 right?! The table is also a list object. Here is the code I am using:
Any ideas on what might be wrong?
Have a great week-end!
Per
I have this code that has always worked for me in the past. It simply loops through all sheets looking for querytables and then re-writes the connection string. I think I initially had it done for Excel 2003 but it should also work for 2010 right?! The table is also a list object. Here is the code I am using:
Code:
Dim qt As QueryTableDim wks As Worksheet
Dim strNewFilePath As String
Dim strNewFileName As String
strNewFilePath = ThisWorkbook.Path
strNewFileName = ThisWorkbook.Name
MsgBox strNewFilePath & strNewFileName
For Each wks In ActiveWorkbook.Worksheets
For Each qt In wks.QueryTable
'MsgBox qt.Connection
With qt
.Connection = Join$(Array("ODBC;DSN=Excel Files;DBQ=", _
strNewFilePath & Application.PathSeparator & strNewFileName, _
";DefaultDir=", strNewFilePath, _
";DriverId=1046;MaxBufferSize=2048;PageTimeout=5;"), vbNullString)
.Refresh BackgroundQuery:=False
End With
Next qt
Next wks
Set qt = Nothing
Set wks = Nothing
Any ideas on what might be wrong?
Have a great week-end!
Per