Hi All,
I have a current ODBC link created a while back that is querying an Excel file. What I would like to do now is to through each ODBC Connection in the workbook and update the Connection String so it uses a different path where another .xls file of the same name is located.
In other words, the current connection string as I see it in Excel (Data>Connections>Connections>1stConn Properties>Definition tab>Connection String) is the following:
DSN=Excel Files;DBQ=C:\TEST\CurrentQuarter.xls;DefaultDir=C:\TEST;DriverId=1046;MaxBufferSize=2048;PageTimeout=5;
and I wish to change it to:
DSN=Excel Files;DBQ=C:\OTHERTEST\CurrentQuarter.xls;DefaultDir=C:\OTHERTEST;DriverId=1046;MaxBufferSize=2048;PageTimeout=5;
I have tried this code:
Am I using an appropriate method on Connection ( .CommandText or .Connection) ? I have the feeling that I am not since VBA throws me an error "Object doesn't support this property or method"
I have seen a similar question asked on MrExcel before : http://www.mrexcel.com/forum/excel-...ns-used-set-odbc-connection-string-query.html
In that case, the Object used is a QueryTable. Should I change Object and use that one ? I was under the impression that that user didn't want to connect to an .xls file..
Any Help would be greatly appreciated !
I have a current ODBC link created a while back that is querying an Excel file. What I would like to do now is to through each ODBC Connection in the workbook and update the Connection String so it uses a different path where another .xls file of the same name is located.
In other words, the current connection string as I see it in Excel (Data>Connections>Connections>1stConn Properties>Definition tab>Connection String) is the following:
DSN=Excel Files;DBQ=C:\TEST\CurrentQuarter.xls;DefaultDir=C:\TEST;DriverId=1046;MaxBufferSize=2048;PageTimeout=5;
and I wish to change it to:
DSN=Excel Files;DBQ=C:\OTHERTEST\CurrentQuarter.xls;DefaultDir=C:\OTHERTEST;DriverId=1046;MaxBufferSize=2048;PageTimeout=5;
I have tried this code:
Code:
Sub SwitchODBCSource()
Dim conn As WorkbookConnection
For Each conn In ActiveWorkbook.Connections
With conn
[FONT=arial black][I] 'I have tried without succes the following 2 properties, without any luck:[/I][/FONT]
.CommandText = "DSN=Excel Files;DBQ=C:\OTHERTEST\CurrentQuarter.xls;DefaultDir=C:\OTHERTEST;DriverId=1046;MaxBufferSize=2048;PageTimeout=5;"
.Connection = "DSN=Excel Files;DBQ=C:\OTHERTEST\CurrentQuarter.xls;DefaultDir=C:\OTHERTEST;DriverId=1046;MaxBufferSize=2048;PageTimeout=5;"
End With
Next conn
Set conn = Nothing
End Sub
Am I using an appropriate method on Connection ( .CommandText or .Connection) ? I have the feeling that I am not since VBA throws me an error "Object doesn't support this property or method"
I have seen a similar question asked on MrExcel before : http://www.mrexcel.com/forum/excel-...ns-used-set-odbc-connection-string-query.html
In that case, the Object used is a QueryTable. Should I change Object and use that one ? I was under the impression that that user didn't want to connect to an .xls file..
Any Help would be greatly appreciated !