是否可以为我的任务在Excel中自动执行Power Queries?

时间:2020-01-22 21:51:55

标签: excel vba automation powerquery

我想从网站上将投资偏好的价格数据提取到多个Excel工作表中。因此,我在Excel工作表中收集了该网站的URL,如下所示:Website format 然后,我在for循环中逐步创建了一个包含每个URL的变量。 现在,我记录了手动执行电源查询的宏。执行完宏后,所需的价格数据被写在另一个Excel工作表中...问题是,这仅在我在代码中手动键入URL时有效,因为在下面的宏中无法识别包含URL的变量代码,但变量对于我的自动化至关重要。代码:

Sub Abfrage()


Dim intFonds As Integer
Let intFonds = 16

Dim strFondsname As String
strFondsname = Range("E" & intFonds).Value

For intFonds = 16 To 32
strFondsname = Range("E" & intFonds).Value

'Selection.Copy
'    ActiveWorkbook.Queries.Add Name:="", Formula:= _
'        "let" & Chr(13) & "" & Chr(10) & "    Quelle = Web.Page_
        '(Web.Contents(strFondsname = Range("E" & intFonds).Value))," & Chr(13) & "" & Chr(10) & "    Data1 = Quelle{1}[Data]," & Chr(13) & "" & Chr(10) & "    #""Geänderter Typ"" = Table.TransformColumnTypes(Data1,{{""Datum"", Int64.Type}, {""Eröffnung"", type number}, {""Schluss"", type number}, {""Tageshoch"", type number}, {""Ta" &  "gestief"", type number}, {""Umsatz (St.)"", Int64.Type}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & "    #""Geänderter Typ"""
'    ActiveWorkbook.Worksheets.Add
'    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
'        "OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Document;Extended Properties=""""" _
'        , Destination:=Range("$A$1")).QueryTable
'        .CommandType = xlCmdSql
'        .CommandText = Array("SELECT * FROM [Document]")
'        .RowNumbers = False
'        .FillAdjacentFormulas = False
'        .PreserveFormatting = True
'        .RefreshOnFileOpen = False
'        .BackgroundQuery = True
'        .RefreshStyle = xlInsertDeleteCells
'        .SavePassword = False
'        .SaveData = True
'        .AdjustColumnWidth = True
'        .RefreshPeriod = 0
'        .PreserveColumnInfo = True
'        .ListObject.DisplayName = "Document2"
'        .Refresh BackgroundQuery:=False
'    End With
'    Sheets("Namen").Select
'    ActiveCell.Offset(1, 0).Select
'    Application.Wait (Now + TimeValue("0:01:00"))
    Next intFonds



End Sub

0 个答案:

没有答案