Html VBA控制Internet Explorer“;对象变量或未设置块变量";

Html VBA控制Internet Explorer“;对象变量或未设置块变量";,html,vba,internet-explorer,frame,Html,Vba,Internet Explorer,Frame,我正在使用VBA控制internet explorer,在我的情况下,我需要实现在网站上单击一个花束的功能。 下面是网站的HTML结构,蓝线就是我想点击的地方。我已经写了一些基本的代码。但是,在Set Bton2=Bton1.Children(4.Children)(1)行出现错误 “未设置对象变量或带块变量”。我也尝试了一些其他的方法,因为我通过“手表”找到了一些可能的线条位置,比如 但它说没有这样的方法或财产。欢迎提供任何建议和解决方案。提前谢谢 Sub openPdf() Dim IE

我正在使用VBA控制internet explorer,在我的情况下,我需要实现在网站上单击一个花束的功能。 下面是网站的HTML结构,蓝线就是我想点击的地方。我已经写了一些基本的代码。但是,在Set Bton2=Bton1.Children(4.Children)(1)行出现错误 “未设置对象变量或带块变量”。我也尝试了一些其他的方法,因为我通过“手表”找到了一些可能的线条位置,比如

但它说没有这样的方法或财产。欢迎提供任何建议和解决方案。提前谢谢

Sub openPdf()

Dim IE As New InternetExplorerMedium
Dim IEDoc As HTMLDocument
Dim Bton1 As Object
Dim Bton2 As Object

IE.Navigate "http://dcv.xxx.xxxx" 'Remplacer par le site de DocPriv ici
IE.Visible = True
Do
Loop Until Not (IE.Busy)

Set IEDoc = IE.document
Set Bton1 = IEDoc.all("frmSommaire1")
Set Bton2 = Bton1.Children(4).Children(1)
Bton1.Children(1).Children(0).Children(9).Children(0).Click
Do
Loop Until Not (IE.Busy)

试试:


我已经找到了解决我问题的办法。请记住,对象/变量并非在所有情况下都有用,最好定义对象的特定类型,如HTMLDocument、HTMLFrameElement和HTMLGenericeElement等。 所以下面的代码是有效的:

Dim IE As New InternetExplorerMedium
Dim IEDoc As HTMLDocument
Dim IEFrm1 As HTMLFrameElement
Dim FRMDoc1 As HTMLDocument
Dim Bton1 As HTMLGenericElement 


IE.Navigate "http://dcv.xxx.xxxx" 'Remplacer par le site de DocPriv ici
IE.Visible = True
Do
Loop Until Not (IE.Busy)

Set IEDoc = IE.document
Set IEFrm1 = IEDoc.all("frmSommaire1")
Set FRMDoc1 = IEFrm1.contentDocument
Set Bton1 = FRMDoc1.getElementById("menu4")
Bton1.all.Item(6).Click
Do
Loop Until Not (IE.Busy)

Stop

谢谢,我找到了一个有效的解决方案。我也测试了你的答案,但它告诉“自动化错误”。你能告诉我如何系统地学习它吗?因为我以前不知道“父窗口”和“执行脚本”。再次感谢。
IEDoc.all("frmSommaire1").document.parentWindow.execScript("clickMenu('4')")
Dim IE As New InternetExplorerMedium
Dim IEDoc As HTMLDocument
Dim IEFrm1 As HTMLFrameElement
Dim FRMDoc1 As HTMLDocument
Dim Bton1 As HTMLGenericElement 


IE.Navigate "http://dcv.xxx.xxxx" 'Remplacer par le site de DocPriv ici
IE.Visible = True
Do
Loop Until Not (IE.Busy)

Set IEDoc = IE.document
Set IEFrm1 = IEDoc.all("frmSommaire1")
Set FRMDoc1 = IEFrm1.contentDocument
Set Bton1 = FRMDoc1.getElementById("menu4")
Bton1.all.Item(6).Click
Do
Loop Until Not (IE.Busy)

Stop