Galera,
tenho uma máquina com um banco mysql conectado na rede local. Como faço para acessar de outra máquina esse meu banco via Vba.
estou usando esse código para conexão localhost ( na mesma máquina onde existe o banco)
Sub ADOExcelSQLServer()
Dim Cn As ADODB.Connection
Dim Server_Name As String
Dim Database_Name As String
Dim User_ID As String
Dim Password As String
Dim SQLStr As String
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Server_Name = "localhost" ' Enter your server name here
Database_Name = "avaliacao" ' Enter your database name here
User_ID = "root" ' enter your user ID here
Password = "root" ' Enter your password here
SQLStr = "SELECT * FROM alternativas" ' Enter your SQL here
Set Cn = New ADODB.Connection
Cn.Open "DRIVER={MySQL ODBC 5.1 Driver};Server=" & Server_Name & ";Database=" & Database_Name & _
";Uid=" & User_ID & ";Pwd=" & Password & ";"
rs.Open SQLStr, Cn, adOpenStatic
With Worksheets("plan1").Range("a1:z500") ' Enter your sheet name and range here
.ClearContents
.CopyFromRecordset rs
End With
rs.Close
Set rs = Nothing
Cn.Close
Set Cn = Nothing
End Sub
Existem mil maneiras de preparar Neston. Invente a sua!
http://www.youtube.com/ExpressoExcel
Postado : 14/09/2011 1:40 pm