【问题标题】:Which .dll contains HTMLElement Class?哪个 .dll 包含 HTMLElement 类?
【发布时间】:2013-12-11 22:37:12
【问题描述】:

我正在使用 Excel (Office 2010) 中的 VBA 在 Internet Explorer 中浏览网页。我的问题是我无法声明 HtmlElement 的实例,例如

Dim myHtmlEl As HtmlElement

返回错误“未定义用户定义类型”。

当我想声明 InternetExplorer 对象的实例时,我已经看到了这个问题。解决方案是在 VBA 编辑器中通过 Tools >> References... >> Microsoft Internet Controls 创建引用。我的理解是,Microsoft Internet Controls 是一个 .dll,具有 InternetExplorer 类的定义。

因此,要创建HtmlElement 对象的实例,我需要引用定义该类的.dllMSDN 表明 .dll系统 Windows 窗体。我链接了它,但该类仍未定义。

我如何知道哪个 .dll 包含 HtmlElement 类?

【问题讨论】:

  • 添加对“MicroSoft HTML 对象库”的引用
  • 如果由于某种原因 Tim 的参考不适用于早期绑定,您可以尝试后期绑定 Dim myHtmlEl As Object
  • 有效。但是您如何查找我需要连接的参考资料?
  • 没有捷径可以找到您需要添加的参考,但如果您用谷歌搜索“VBA HTMLelement”,您可能会在前六次点击中找到答案。

标签: internet-explorer vba excel


【解决方案1】:

late binding solution 可能适合您的需求。

Dim myHtmlElement As Variant 
Dim IE As Variant 

Set IE = CreateObject("InternetExplorer.Application") 
IE.Visible = True 

IE.Navigate "http://www.stackoverflow.com/" 

' Wait while site is loading
While IE.Busy: DoEvents: Wend

' Get An Element
Set myHtmlElement = IE.Document.getElementById("myInput") 

' Set the value of an element
If Not myHtmlElement Is Nothing Then myHtmlElement.Value = ActiveCell.Value

' Click a button
Set myHtmlElement = IE.Document.getElementById("searchButton") 
myHtmlElement.Click

' Wait while site is loading
While IE.Busy: DoEvents: Wend

' Navigate the IE object 
Dim i As Integer 
For i = 0 To IE.Document.getElementsByTagName("a").Length - 1 
    If IE.Document.getElementsByTagName("div").Item(i).innerText Like "ab*" Then 
        ' Do Something
    End If
Next

以上代码基于链接的 MSDN 论坛。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-13
    • 2011-01-31
    相关资源
    最近更新 更多