I am using the below connection string in my excel VBA. But I need to set it up in a way that the database and server is picked from an cell like A$1$. So I can change the database details when ever I need.
Function Connect(Server As String, _
Database As String) As Boolean
Set CN = New ADODB.Connection
On Error Resume Next
With CN
' Create connecting string
.ConnectionString = "Provider=SQLOLEDB.1;" & _
"Integrated Security=SSPI;" & _
"Server=" & Server & ";" & _
"Database=" & Database & ";"
' Open connection
.Open
End With
' Check connection state
If CN.State = 0 Then
Connect = False
Else
Connect = True
End If
End Function
Thanks in advance