Dim Conn As String
Conn = "ODBC;DRIVER=SQL Server;" & _
"SERVER=<server>;" & _
"UID=<user>;" & _
"PWD=<pass>;" & _
"APP=Microsoft Office 2010;" & _
"WSID=<Host>;" & _
"DATABASE=<database>"
With ActiveWorkbook.Connections("SQLCommand").OdbcConnection
.BackgroundQuery = True
.CommandText = Sheets("SQLString").Range("A2").Value
.CommandType = xlCmdSql
.Connection = Conn
.RefreshOnFileOpen = False
.SavePassword = True
.SourceConnectionFile = ""
.SourceDataFile = ""
.ServerCredentialsMethod = xlCredentialsMethodIntegrated
.AlwaysUseConnectionFile = False
End With
With ActiveWorkbook.Connections("SQLCommand")
.Name = "SQLCommand"
.Description = ""
End With
' ---------------------------------
' --------- REFRESH ODBC ----------
' ---------------------------------
ActiveWorkbook.Connections("SQLCommand").Refresh
Application.ScreenUpdating = True
Bookmarks