I have an excel workbook that is linked to an open Power BI file.
The connection name is "mtbsql6??v-dev_mssqlinst01 PRS Model" and the connection string is
"Provider=MSOLAP.8;Integrated Security=SSPI;Persist Security Info=True;User ID="";Initial Catalog=2a527000-c71f-4b0d-8506-36d1799ec663;Data Source=localhost:6514?;Location=localhost:6514?;MDX Compatibility=1;Safety Options=2;MDX Missing Member Mode=Error;Update Isolation Level=2".
I need to update the local host number which I already have in a variable. Is it an OLEDB connection? Have tried some below code but it's failing. Got this code from another answer on stack overflow. It is failing on the line marked as ##.
Dim ConnectionString As String
ConnectionString = UpdatedString (This is stored in a variable)
UpdateQueryConnectionString ConnectionString
Sub UpdateQueryConnectionString(ConnectionString As String)
Dim cn As WorkbookConnection
Dim oledbCn As OLEDBConnection
Set cn = ThisWorkbook.Connections("mtbsql6??v-dev_mssqlinst01 PRS Model")
Set oledbCn = cn.OLEDBConnection
oledbCn.Connection = ConnectionString ###
End Sub
Thanks for any help.