vba:ODBC和Where语句

时间:2015-07-27 19:18:22

标签: excel vba odbc

我正在使用和ODBC连接将数据导入excel。进口运作良好。但是,它是很多数据,我希望使用ODBC导入中的where语句来限制它。问题是我的条件是一个改变值的变量。有没有办法做到这一点?

我的代码摘录如下:

Dim ActBDO
ActBDO = Sheets("Summary").Range("E3").Value

ActiveWorkbook.Worksheets.Add
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
    "ODBC;DSN=   ...
    "SELECT ..." & Chr(13) & "" & Chr(10) & "FROM ..." & Chr(13) & "" & Chr(10) & "WHERE (ReportingProductDataTable.BDO=actbdo)"* & Chr(13) & "" & Chr(10) & "ORDER BY ...")
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .PreserveColumnInfo = True
    .ListObject.DisplayName = "Table_Query"
    .Refresh BackgroundQuery:=False
End With

0 个答案:

没有答案