【问题标题】:How is it possible to get the title of a webpage using vba?如何使用 vba 获取网页的标题?
【发布时间】:2019-11-07 11:57:01
【问题描述】:

这是我为获取计算机上所有打开的 Internet Explorer 页面的标题而编写的代码。

Dim objShell As Object
Dim IE_count As Variant
Dim my_url As Variant
Dim my_title As Variant
Dim x As Integer

    Set objShell = CreateObject("Shell.Application")
    IE_count = objShell.Windows.Count
    MsgBox ("The number of pages is: " & IE_count)

    For x = 0 To (IE_count - 1)
    On Error Resume Next
    my_url = objShell.Windows(x).Document.Location
    my_title = objShell.Windows(x).Document.Title
    MsgBox ("The title of this page is: " & my_url)

我的代码中的第一个 MsgBox 实际上显示了正确的 IE_count 数量(代表打开的窗口数量)。

但是,我在显示 my_url 或 my_title 变量时遇到了一些问题。 与这些字段相关的 MsgBox 只是显示“此页面的标题是:”,“是”之后没有任何内容。

您知道如何修复此错误以获取窗口的 url 或标题吗?

PS:我什至尝试将 my_url 和 my_title 的数据类型从变量更改为字符串,但没有任何改变。

非常感谢任何帮助!谢谢你:)

【问题讨论】:

    标签: html excel vba internet-explorer


    【解决方案1】:

    尝试删除此行:

    Dim x As Integer
    

    编辑:

    您使用的是哪个版本的 Excel?

    也许 '''Dim x As Variant''' 会起作用。

    【讨论】:

    • 我无法删除变量 x 的声明。如果我在没有任何变量 x 声明的情况下运行代码,我会收到错误“变量未定义”@JustinLane
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-23
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 2015-06-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多