I built an Excel-based tool that uses ODBC connections and querytables to pull data from a SQL Server (2014). This tool has to be compatible with Mac Office 2016 (hence the ODBC and querytables).
I'm struggling with testing whether the user can connect to the SQL Server. With the ODBC connection, if it fails to connect, a SQL Server error login dialog opens and then a login dialog opens before my error handling can take effect.
Every solution to this issue that I found uses either ADODB (which isn't compatible with Mac) or is a solution to Access VBA. This answer talks about TCP connections, but I was unable to find anything about TCP and VBA that looked compatible with Mac.
Does anyone know of a way to test a SQL Server connection that would be compatible with Office for Mac 2016 using VBA?
An example of how I'm using ODBC and querytables to connect to SQL Server.
Sub main()
    On Error GoTo err1
    Dim connstring As String
    Dim sqlstring As String
    Dim dArr As Variant
    Dim qt As QueryTable
    connstring = "ODBC;DRIVER={SQL Server};SERVER=SERVERNAME;DATABASE=master;Trusted_Connection=yes"
    sqlstring = "SELECT 1"
    Set qt = ActiveSheet.QueryTables.Add(Connection:=connstring, Destination:=ThisWorkbook.Sheets(1).Range("A1"), Sql:=sqlstring)
    With qt
      .BackgroundQuery = False
      .RowNumbers = False
      .Refresh
    End With
    dArr = qt.ResultRange.Value
    qt.Delete
    ThisWorkbook.Sheets(1).Cells.Clear
    Exit Sub
err1:
Stop
End Sub

