Hi everyone,
I'm trying to operate a macro that loops through all connections strings in a workbook and defines them to their base form as defined in "DBPath" range below. Is there any way to do this? I get a run time error '13' type mismatch with what I'm currently trying below. Any help would be much appreciated!
Sub ADODBconnectionreset()
Dim cn As ADODB.Connection
Dim DBpath As String
'updates connection path to path defined in DBPath to keep workbook compatible across multiple versions of Excel
DBpath = ThisWorkbook.Worksheets("ProjectDetails").Range("DBPath").Value
For Each cn In ThisWorkbook.Connections
cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Mode=Read; Data Source=" & DBpath & ";"
Next cn
End Sub
I'm trying to operate a macro that loops through all connections strings in a workbook and defines them to their base form as defined in "DBPath" range below. Is there any way to do this? I get a run time error '13' type mismatch with what I'm currently trying below. Any help would be much appreciated!
Sub ADODBconnectionreset()
Dim cn As ADODB.Connection
Dim DBpath As String
'updates connection path to path defined in DBPath to keep workbook compatible across multiple versions of Excel
DBpath = ThisWorkbook.Worksheets("ProjectDetails").Range("DBPath").Value
For Each cn In ThisWorkbook.Connections
cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Mode=Read; Data Source=" & DBpath & ";"
Next cn
End Sub