簡體   English   中英

從單元格中的網址動態進行Web查詢

[英]Dynamics webquery from url in cells

我搜索了互聯網,但找不到任何地方的單元格鏈接動態查詢。 在Excel中,我有生成此數據的webquery:

我在Excel Sheet(“ CustomReport”)中有數據:

SalesOrder  Value1      Value2      Value3     Links
1           Jonas       Station1    8          https://x.com=1
2           Greg        Station1    5          https://x.com=2
3           Anton       Station1    1          https://x.com=3
...         ...         ...         ...        ...

刷新時此查詢中的行數始終不同。

基於此網絡查詢,我需要在宏中生成動態網絡查詢。 例如:DynamicQuery1將數據從報告https ://x.com=1保存到工作表名稱“訂單”,該數據從A1開始並以A {X}值結尾(報告的行數不同)。

DynamicQuery2將數據從報表https: //x.com=2保存到同一工作表“訂單”,但從A {X + 1}開始。

我有這樣的宏,但它僅適用於第一行。

  

而且我需要每1小時刷新一次此宏。 任何人都可以基於這種方式給我宏嗎?

要遍歷單元格,請使用:

dim c as range, DataSpot as range
set c = Sheets("CustomReport").Range("E2")
while c.value <>""
    url = c.value
    set DataSpot=cells(sheets("orders").Range("A1").SpecialCells(xlLastCell).row+1,1)
    ' Web Query Code goes here
    set c=c.offset(1,0)
wend

在數據查詢中,使用:

Destination:=Range(DataSpot.Address))

子測試()

Dim URL As String

URL = Sheets("CustomReport").Range("E2").Value

Sheets("Sheet1").Select
Dim c As Range, DataSpot As Range
Set c = Sheets("CustomReport").Range("E2")
While c.Value <> ""
    Set DataSpot = Cells(Sheets("Sorders").Range("A1").SpecialCells(xlLastCell).Row + 1, 1)
        With ActiveSheet.QueryTables.Add(Connection:="URL;" & URL, Destination:=Range(DataSpot.Address))
         .Name = "team2289_2"
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = False
            .RefreshOnFileOpen = False
            .BackgroundQuery = True
            .RefreshStyle = xlOverwriteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .WebSelectionType = xlEntirePage
            .WebFormatting = xlWebFormattingAll
            .WebPreFormattedTextToColumns = True
            .WebConsecutiveDelimitersAsOne = True
            .WebSingleBlockTextImport = False
            .WebDisableDateRecognition = True
            .WebDisableRedirections = False
             .Refresh BackgroundQuery:=False
        End With
        Set r = r.Offset(1, 0)
Wend

結束子

我放入您的代碼,並使用以下命令進行調試:Set r = r.Offset(1,0)

我做錯了什么?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM