當然可以
參考這邊的說明 "tomliu888.blogspot.tw/2016/04/excel-ms-sql-vba.html"
因不能貼連結, 所以把內容貼上來
Sub connectSQL()
Dim Conn As ADODB.Connection
Dim sConnect As String
Dim strSqlInstance As String
Dim strSqlDB As String
Dim strSqlUser As String
Dim strSqlPWD As String
' strSqlInstance = "SERVER_NAME\INSTANCE"
' 如果伺服器只有裝一次 SQL,就只要輸入伺服器名稱
strSqlInstance = "Your SQL Server Name or IP Address"
strSqlDB = "Your Database Name"
strSqlUser = "sa"
strSqlPWD = "password"
sConnect = "Provider=SQLOLEDB"
sConnect = sConnect & ";DATA SOURCE=" & strSqlInstance & ";Initial Catalog=" & strSqlDB
' 如果把 User ID=...;Password=... 改成 "Integrated Security=sspi;",認證方式就變成 AD 登入帳號
sConnect = sConnect & ";User ID=" & strSqlUser & ";Password=" & strSqlPWD & ";"
Set Conn = New ADODB.Connection
Conn.ConnectionString = sConnect
Conn.Open
' 這裡輸入你處理 SQL 的命令
Conn.Close
End Sub