0
我在我的Excel VBA中使用下面的連接字符串。但我需要以一種方式設置它,即從A $ 1 $等單元中選取數據庫和服務器。所以我可以在需要時更改數據庫的詳細信息。在連接字符串中使用單元格引用
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
在此先感謝
感謝伯尼......我現在是否可以連... – 2014-10-20 15:27:12
乾杯,隊友。快樂的編碼。 – bernie 2014-10-20 16:06:21