我一直在网上搜索答案,但到目前为止找不到任何有用的东西。问题实际上就像标题一样简单。我在网页中有一些元素,我希望我的宏仅在它们具有/不具有特定类时才执行操作。
更准确地说,每当您在页面内移动时,这些项目都会被隐藏并添加一个隐藏类,因为它们仍然可以找到 getelementbyid 我有点无法验证该元素是否可见(隐藏类已删除)或不。
我认为不需要任何代码?这只是切换隐藏类的一些简单元素,我很好奇是否可以使用 vba 进行检查。
提前非常感谢!
我一直在网上搜索答案,但到目前为止找不到任何有用的东西。问题实际上就像标题一样简单。我在网页中有一些元素,我希望我的宏仅在它们具有/不具有特定类时才执行操作。
更准确地说,每当您在页面内移动时,这些项目都会被隐藏并添加一个隐藏类,因为它们仍然可以找到 getelementbyid 我有点无法验证该元素是否可见(隐藏类已删除)或不。
我认为不需要任何代码?这只是切换隐藏类的一些简单元素,我很好奇是否可以使用 vba 进行检查。
提前非常感谢!
我想我会在回答中为你充实它,因为我留下的评论并没有提供太多信息。
Set IE = CreateObject("InternetExplorer.Application")
Dim URL as String
URL = 'your URL here
Dim HTMLdoc As HTMLDocument
With IE
.Silent = True
.Visible = True
.Navigate URL
Do Until .readyState = 4
DoEvents
Loop
Set HTMLdoc = .Document
End With
Dim hiddenElements As HTMLElementCollection
Set hiddenElements = HTMLdoc.getElementsByClassName("your class name") 'add this to a watch or inspect your locals
'Alternatively, you can print them all to the immediate window
Dim hiddenElement as Variant
For Each hiddenElement in hiddenElements
Debug.Print hiddenElement.Value 'or .innerHTML or whatever you want here
Next hiddenElement
如果您正在单步执行代码,这很有效,但是使用HTMLDocument
并且readyState
在实时更新网页时可能会很麻烦,因此MSXML.XMLHTTP60
是首选。.