VBA查询mysql

时间:2017-01-22 17:15:33

标签: mysql vba odbc

我是mysql的新手。我设法通过宏录制查询我们的mysql数据库中的一些数据但不知何故,我想编辑 commandtext 来添加一些" JOIN,WHERE等"。以下是录制的宏工作正常。谢谢!

Sub Macro1()

With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array( _
    "OLEDB;Provider=MSDASQL.1;Persist Security Info=True;Data Source=MySQL Excel;Extended Properties=""DSN=MySQL Excel;"";Initial Catalog=Mfg" _
    , ""), Destination:=Range("$A$1")).QueryTable
    .CommandType = xlCmdTable
    .CommandText = Array("`Mfg`.`kgbRun`")
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .PreserveColumnInfo = True
    .SourceConnectionFile = _
    "C:\Users\atanacic\Documents\My Data Sources\Mfg.odc"
    .ListObject.DisplayName = "Table_Mfg15"
    .Refresh BackgroundQuery:=False
End With

End Sub

0 个答案:

没有答案