1

I am using VBA to control the internet explorer, and in my case I need to realize the function of click a boutton on the website. Below is the structure HTML of the website, and the blue line is just the place where I want to click. I have written some basic code. However it comes an error at the line Set Bton2 = Bton1.Children(4).Children(1) "Object variable or With block variable not set". i have also tried some ither ways for I have found some possible position of the line by "Watch", like

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

But it says no such a methode or property. Any advice and solution is welcome. Thanks in advance.

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)

etc

Format HTML

2 Answers 2

1

I have found a solution to my problem. Remember that object/variant is not useful in all cases, and it would be better to define the specific type of the object, like HTMLDocument, HTMLFrameElement and HTMLGenericElement etc. So the code below works:

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
Sign up to request clarification or add additional context in comments.

Comments

0

Try:

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

1 Comment

Thanks, I have found a solution which works. I have also tested your answer but it tells "Automation Error". Could you please tell me how to learn it systematically? for I hadn't known "parentWindow" et "execScript" before. Thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.