2017-01-29 16 views
0

我想用excel vba来控制Internet Explorer对象。如何通过excel传递信息到url vba

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

  • 时限即 “人民日报”
  • 开始日期,即 “2016年1月1日”
  • 结束日期,即 “31/12/2016”

如何用excel vba做到这一点?

我有这个代码打开URL

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"
  • 开始日期,即 “2016年1月1日”

任何人都可以帮忙吗?

+0

自定义的约会,你道琼斯网页对话框列出的内容不会将您选择的日期嵌入到网页网址中。如果是这种情况,您将无法使用您提出的方法进行操作。 – Amorpheuses

回答

0

我已经想出了这个简单的宏(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 
+0

感谢您的信息。但是,在Set IEdoc = IE.Document上出现“运行时错误”-2147467259(80004005)。我该如何解决这个问题? –