WoorkBookQuery用户定义的类型未定义

时间:2016-03-03 20:33:36

标签: excel vba powerquery

我正在尝试通过Macro从powerquery加载我在Windows剪贴板中的查询。但我不能测试它,因为我没有参考,我不知道如何猜测它是谁:

Sub readClipboard()
'Tools -> References -> Microsoft Forms 2.0 Object Library
'of you will get a "Compile error: user-defined type not defined"
Dim DataObj As New MSForms.DataObject
Dim S As String
Dim currentSheet As Worksheet
Dim qry As WorkbookQuery

Set currentSheet = Sheets.Add(After:=ActiveSheet)

DataObj.GetFromClipboard
S = DataObj.GetText

Set qry = ThisWorkbook.Queries.Add("Prueba", S, "Nose")

With currentSheet.ListObjects.Add(SourceType:=0, Source:= _
    "OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=" & Query.Name _
    , Destination:=Range("$A$1")).QueryTable
    .CommandType = xlCmdDefault
    .CommandText = Array("SELECT * FROM [" & Query.Name & "]")
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .PreserveColumnInfo = False
    .Refresh BackgroundQuery:=False
End With

End Sub

0 个答案:

没有答案