Html 如何使用vba获取网页标题?
以下是我编写的代码,用于获取计算机上所有打开的internet explorer页面的标题Html 如何使用vba获取网页标题?,html,excel,vba,internet-explorer,Html,Excel,Vba,Internet Explorer,以下是我编写的代码,用于获取计算机上所有打开的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
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_计数(表示打开的窗口数)
但是,我在显示my_url或my_title变量时遇到一些问题。
与这些字段相关的MsgBox只显示“此页面的标题为:”并且“是”后面没有任何内容
您知道如何修复此错误以获取窗口的url或标题吗
PS:我甚至尝试将我的url和标题的数据类型从variant改为string,但没有任何改变
我真的很感激任何帮助!谢谢:)尝试删除此行:
Dim x As Integer
编辑:
您使用的是什么版本的Excel
也许“Dim x作为变体”会起作用 我无法删除变量x的贴花。如果我在没有任何变量x声明的情况下运行代码,我会得到错误“variable not defined”@JustinLane