【问题标题】:how to pass information to url via excel vba如何通过excel vba将信息传递给url
【发布时间】:2017-01-29 16:41:32
【问题描述】:

我想使用 excel vba 来控制 Internet Explorer 对象。

我们可以手动设置在“https://www.investing.com/indices/us-30-historical-data

  • 时间范围,即“每日”
  • 开始日期,即“01/01/2016”
  • 结束日期,即“31/12/2016”

如何用 excel vba 做到这一点?

我有这段代码可以打开网址

InfiniteLoop = True
Set ie = CreateObject("InternetExplorer.Application")
With ie
    .Visible = True
    .Navigate myURLLink ' should work for any URL

    SleepTime = 10000
    Do
        DoEvents
        Sleep (SleepTime)
        If ie.ReadyState >= 4 Then
            Exit Do
        End If
    Loop Until InfiniteLoop = False
End With

但我不知道如何通过

  • 时间范围,即“每日”
  • 开始日期,即“01/01/2016”
  • 开始日期,即“01/01/2016”

谁能帮忙?

【问题讨论】:

  • 您列出的 Dow Jones 页面上的自定义日期对话框不会将您选择的日期嵌入到页面 URL 中。如果是这种情况,您将无法使用您提议的方法来做到这一点。

标签: excel internet-explorer vba


【解决方案1】:

我想出了这个简单的宏 (Excel 2010) 来导航到该位置并更改日期和数据间隔,希望它会有所帮助:

Sub test()
Dim IE As InternetExplorer
Dim IEdoc As Object
Dim IEElement As Object

Set IE = New InternetExplorer 'initialize Internet Explorer

IE.Navigate "https://www.investing.com/indices/us-30-historical-data" 'Navigate to URL
IE.Visible = True

Set IEdoc = IE.Document

Set IEElement = IEdoc.GEtelementbyID("picker") ' navigate to date input
IEElement.Value = "01/01/2016 - 01/01/2017"

Set IEElement = IEdoc.GEtelementbyID("widget") ' navigate to date widget
IEElement.Click
Set IEElement = IEdoc.GEtelementbyID("applyBtn") ' navigate to Apply button to save the dates
IEElement.Click


Set IEElement = IEdoc.GEtelementbyID("data_interval") ' navigate to Interval picker
IEElement.Value = "Daily"

End Sub

【讨论】:

  • 感谢您的帖子。但我在 Set IEdoc = IE.Document 上收到“运行时错误 '-2147467259 (80004005)”。我该如何解决这个问题?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-02
  • 2021-04-17
  • 2019-10-18
相关资源
最近更新 更多