简体   繁体   English

QueryTables.Add 动态链接引用单元格

[英]QueryTables.Add dynamic link referencing cells

The link I want to use is "https://xxx/xxx/xxx/reporting?start_date=2022-05-15+00&end_date=2022-05-21+00" whereas the start_date=Simba1 and the end_date=Simba2我要使用的链接是“https://xxx/xxx/xxx/reporting?start_date=2022-05-15+00&end_date=2022-05-21+00”,而 start_date=Simba1 和 end_date=Simba2

Simba 1 and simba 2 are date cells. Simba 1 和 simba 2 是日期单元格。

'Download Simba Table' '下载辛巴表'

Sheets("SIMBA Data").Select
Cells.Select
Selection.ClearContents
Range("A1").Select
With ActiveSheet.QueryTables.Add(Connection:= _
    "URL;https://xxx/xxx/xxx/reporting?" _
    & "start_date=" & Simba1 _
    & "&end_date=" & Simba2 & "", Destination:=Range("$A$1"))
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .WebSelectionType = xlSpecifiedTables
    .WebFormatting = xlWebFormattingNone
    .WebTables = "1"
    .WebPreFormattedTextToColumns = True
    .WebConsecutiveDelimitersAsOne = True
    .WebSingleBlockTextImport = False
    .WebDisableDateRecognition = False
    .WebDisableRedirections = False
    .Refresh BackgroundQuery:=False
End With

Adding the following with the answer that Tim posted, resolved my issue!!在蒂姆发布的答案中添加以下内容,解决了我的问题!

Dim Simba1 As Variant

Simba1 = Range("'Report Controls'!$C$1").Value

Dim Simba2 As Variant

Simba2 = Range("'Report Controls'!$C$2").Value

Use Format()使用Format()

With ActiveSheet.QueryTables.Add(Connection:= _
    "URL;https://xxx/xxx/xxx/reporting?" _
    & "start_date=" & Format(Simba1, "yyyy-mm-dd") _
    & "+00&end_date=" & Format(Simba2, "yyyy-mm-dd") & "+00", _
    Destination:=Range("$A$1"))
   
    '...
    '...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM