Just like the title states what would be VBA to change a connection string of all the query's in a workbook?
Just like the title states what would be VBA to change a connection string of all the query's in a workbook?
That depends on whether the strings are in code or cells.
I expect the student to do their homework and find all the errrors I leeve in.
Please take the time to read the Forum FAQ
I am going to go with cells. They are access query's that are imported into the spreadsheet.
Select a Cell with a connection string to be replaced. Press Ctrl+H, then click the Advanced button.
I expect the student to do their homework and find all the errrors I leeve in.
Please take the time to read the Forum FAQ
SOmething like this:
[VBA]Sub ChangeAllConnections(sNewConn As String)
Dim oLo As ListObject
Dim oSh As Worksheet
Dim oQt As QueryTable
For Each oSh In Worksheets
'connections can be in a listobject (table)
For Each oLo In oSh.ListObjects
oLo.QueryTable.Connection = sNewConn
Next
'but also outside a listobject (querues created in Excel 2003 or before; web queries)
For Each oQt In oSh.QueryTables
oQt.Connection = sNewConn
Next
Next
End Sub
[/VBA]
or ?
[VBA]
Sub M_snb()
For Each cn In ThisWorkbook.Connections
cn.OLEDBConnection.Connection = Replace(cn.OLEDBConnection.Connection, "G:\OF\", "G:\")
Next
End Sub
[/VBA]
That assumes they are all OLEDB and not ODBC, of course.
Be as you wish to seem