2014-04-18 51 views
1

我使用VBA来控制Internet Explorer,然后在我的情况,我需要实现点击网站上的boutton的功能。 下面是该网站的结构HTML,和蓝线就是我想要点击的地方。我写了一些基本的代码。但是它是在线路集Bton2 = Bton1.Children(4)。儿童(1) 错误“对象未设置变量或With块变量”。我也尝试过的一些ither途径,我发现用“手表”行的一些可能的位置,像VBA控制Internet Explorer“对象变量或带块变量未设置”

Set Test = Bton1.contentDocument.DocumentElement.all(9) 

但是它说没有这样的梅索德或财产。任何建议和解决方案是受欢迎的提前致谢。

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) 

Format HTML

回答

0

尝试:

IEDoc.all("frmSommaire1").document.parentWindow.execScript("clickMenu('4')") 
+0

谢谢,我找到了可行的解决方案。我也测试了你的答案,但它告诉“自动化错误”。你能告诉我如何系统地学习它吗?因为我之前并不知道“parentWindow”和“execScript”。再次感谢。 – Esct

1

我已经找到了解决我的问题。请记住,对象/变种是不是在所有情况下是有用的,这将是更好地定义特定类型的对象,像HTMLDocument的,HTMLFrameElement和HTMLGenericElement等 所以下面的代码工作:

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 
相关问题