点击Excel VBA的JavaScript按钮
Excel VBA click JavaScript button
有人能告诉我VBA代码点击这个网页上的"复制到剪贴板"按钮吗?按钮有一个元素id="ToolTables_example_0",但我不知道如何从Excel执行脚本。我试过重新设计许多不同的VBA代码,我发现,但没有运气。看起来应该这么简单!谢谢!
https://spotwx.com/products/grib_index.php?model=nam_awphys& lat = 30.26678,朗= -97.76905和tz =美国/Chicago&显示=表
下面的代码要求你使用VBE的Tools►References命令将Microsoft HTML Object库和Microsoft Internet控件添加到你的项目中。
这里有两种单击该按钮的方法。
Sub clickIt()
Dim a As Long, u As String, till As Double
Dim el As MSHTML.IHTMLElement, ie As New SHDocVw.InternetExplorer
u = "https://spotwx.com/products/grib_index.php?model=nam_awphys&lat=30.26678&lon=-97.76905&tz=America/Chicago&display=table"
ie.Silent = True
ie.Visible = True
ie.navigate u
Do While ie.Busy Or ie.readyState <> 4: DoEvents: Loop
'wait an extra second or so (this usually isn't necessary but helped with this page)
till = Timer + 1
Do While Timer < till: DoEvents: Loop
'Method 1: Loop through all the A elements looking for the right ID
For a = 0 To ie.document.getElementsByTagName("a").Length - 1
With ie.document.getElementsByTagName("a")(a)
If .ID = "ToolTables_example_0" Then
Debug.Print "found ToolTables_example_0 in a loop"
.Click
'the table data should be on the clipboard
Exit For
End If
End With
Next a
'Method 2: Locate the right A element using its ID directly
On Error Resume Next
Set el = ie.document.getElementById("ToolTables_example_0")
On Error GoTo 0
If Not el Is Nothing Then
Debug.Print "found ToolTables_example_0 directly"
el.Click
'the table data should be on the clipboard
End If
ie.Quit
Set ie = Nothing
End Sub
我不能完全测试,因为我的ie没有安装Adobe FlashPlayer(我宁愿保持这种方式)。如果您可以手动打开Internet Explorer,导航到该页,单击按钮,然后将复制到剪贴板的内容粘贴回Excel工作表,那么我认为它没有理由不工作
相关文章:
- Javascript按钮下拉列表
- ASP.NET通过单击JavaScript按钮触发c#事件
- JavaScript按钮/输入/函数,字符串反转
- 测试一个简单的javascript按钮
- 如果函数返回True,则显示Javascript按钮
- 用Javascript按钮替换Javascript超链接
- 从页面javascript按钮运行Node.JS
- 如何在asp.net上应用javascript按钮点击
- Javascript按钮href注入
- 计时器自动运行,而不是单击javascript按钮
- Javascript按钮,在html文本区域中插入一个大黑点(•)
- 单击javascript按钮显示/隐藏Div元素
- 单击Javascript按钮,将值添加到文本框中
- visualforce页面javascript按钮点击不起作用
- 使javascript按钮隐藏或显示内容切换
- 使用 Scrapy 模拟 JavaScript 按钮点击
- Javascript按钮禁用并启用特定时间
- 如果未输入任何内容,则使 JavaScript 按钮不执行任何操作
- 当表为空时禁用 JavaScript 按钮
- javascript按钮在html中不起作用