ADODB is NOT supported in Mac Excel 2011, but ODBC works in conjunction with a 3rd party driver.
I got my ODBC drivers from ActualTech. Download and install their program and you'll have the necessary drivers for connecting to SQL servers and databases (Free to try, $35 to purchase).
The following code creates a connection to a mySQL database, and returns information from the database into Cell A1:
Dim connstring as String
Dim sqlstring as String
connstring = "ODBC;DRIVER={Actual Open Source Databases};" _
& "SERVER=<server_location>;DATABASE=<database>;" _
& "UID=<userID>;PWD=<password>;Port=3306"
sqlstring = "select * from <database_table>"
With ActiveSheet.QueryTables.Add(Connection:=connstring, Destination:=Range("A1"), Sql:=sqlstring)
.BackgroundQuery = False
.Refresh
End With
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…