macro to navigate IE browser and click on checkbox and update button

AmitParekh

New Member
Joined
Jan 17, 2013
Messages
21
Hi All,


I have prepared a macro to open and navigate through one of the web page. I am got stuck on below case were I want to click on Update button and click on checkbox to deselect the checkbox. Below is the source code of the web page.
Checkbox:
span DesignTimeID="chkNotifyClient" input id="chkNotifyClient" type="checkbox" name="chkNotifyClient" checked="checked" label for="chkNotifyClient">Notify client or Other Recipient (Note: Comment will be sent as e-mail body) label span td
Update button:
input type="submit" name="UpdateTask" value="Update" *******="Refresh();DisableButton();WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("UpdateTask", "", true, "", "", false, false))" id="UpdateTask" class="ButtonDefault" DesignTimeID="UpdateTask" onMouseDown="this.className='ButtonDefault ButtonMouseDown';" onMouseUp="this.className='ButtonDefault ButtonDefault';" **********="this.className='ButtonDefault ButtonDefault';" IsDefault="False" style="height:16px;"


I have tried many options like IE.document.all("UpdateTask").Click OR IE.document.all("Refresh();DisableButton();WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("UpdateTask", "", true, "", "", false, false))").Click but all my effort got waste, its not working.


Thanks in advance for any help!
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
For the checkbox, try something like:
Code:
Dim cb As Object
Set cb = IE.document.getElementById("chkNotifyClient")
cb.Checked = False
For the button:
Code:
Dim ub As Object
Set ub = IE.document.getElementsByName("UpdateTask")(0)
'ub.Focus  'Might need this
ub.Click
'ub.Blue   'Might need this
If that doesn't work I would need the URL and be able to access the web page directly to help you further.
 
Upvote 0
Hi John,

I have tried above code but getting error message:

Run-time error '91': Object Variable or with block variable not set

I am using excel 2007 and reference library checked "Microsoft HTML Object Library" and Microsoft ActiveX Data Objects 2.0 Library. Don't have Microsoft Internet Controls library.

Please advise.
 
Upvote 0
Is the IE object defined? Set IE = CreateObject("InternetExplorer.Application")

That isn't the whole code you would need. It was just a snippet to show you the basics of interacting with the two HTML elements you are having problems with. For a start you need to define the IE object which is the InternetExplorer object (see above code) opened on the web page, but I expect you know that because you are already using IE in your OP. You don't need to set a reference to the MS Internet Controls library if you are using late binding of the IE object (see above code), nor for any other library. If the reference isn't listed and you want to set a reference to it, browse to and select C:\Windows\system32\shdocvw.dll.
 
Upvote 0
yes John, I have defined the IE and added the Microsoft internet controls reference also. But still its giving me the same error message.
 
Upvote 0
Can you post the whole code, including the URL of the web site? If the web site requires a login I won't be able to help.
 
Upvote 0
Oh... the web site is not access-able remotely, its linked with the some server. Below is the code which I have been able to write so far.

Private Declare Sub SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long)
Sub Trackpoint()
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.navigate URL:="https://trackpoint2.com/MUMBAI/"
Do Until .readyState = 4
DoEvents
Loop
Set mytextfield1 = .document.all.Item("UserName")
mytextfield1.Value = Sheets("test_vba").Range("a1").Value
Set mytextfield2 = .document.all.Item("UserPassword")
mytextfield2.Value = Sheets("test_vba").Range("a2").Value
IE.document.all("submit").Click
Do Until .readyState = 4
DoEvents
Loop
Application.Wait (Now + TimeValue("0:01:00"))
IE.Visible = True
For i=1 to 21
SendKeys "+{TAB}", True
Next i
SendKeys "{Enter}", True
SendKeys "{Enter}", True
SendKeys "{Enter}", True
'SendKeys "{BROWSER_REFRESH}", True
Application.Wait (Now + TimeValue("0:00:10"))
SendKeys "{ESC}", True
Application.Wait (Now + TimeValue("0:00:10"))
For a = 1 To 65
SendKeys "{TAB}", True '1
Next a
SendKeys "{Enter}", True
Application.Wait (Now + TimeValue("0:00:10"))
SetCursorPos 956, 285 'x and y position
Application.Wait (Now + TimeValue("0:00:05"))
For b = 1 To 21
SendKeys "{TAB}", True '1
Next b
SendKeys "{Enter}", True
Application.Wait (Now + TimeValue("0:00:10"))
For c = 1 To 25
SendKeys "{TAB}", True '1
Next c
SendKeys "{DOWN}", True
SendKeys "{DOWN}", True
SendKeys "{DOWN}", True
'IE.document.all("chkNotifyClient").Click
'IE.document.all("UpdateTask").Click
Dim cb As Object
Set cb = IE.document.getElementById("chkNotifyClient")
cb.Checked = False

Dim ub As Object
Set ub = IE.document.getElementsByName("UpdateTask")(0)
'ub.Focus 'Might need this
ub.Click
'ub.Blue 'Might need this
End With
End Sub

I have got stuck with CheckBox check and clicking on update button. I can not use tab movement here as fields won't be same for all cases which I want to complete.
 
Upvote 0
Code:
Dim cb As Object
Set cb = IE.document.getElementById("chkNotifyClient")
cb.Checked = False

Dim ub As Object
Set ub = IE.document.getElementsByName("UpdateTask")(0)
'ub.Focus 'Might need this
ub.Click
'ub.Blue 'Might need this
I have tried above code but getting error message:

Run-time error '91': Object Variable or with block variable not set

Which line causes the error?
If the Set cb... line, it means the element with id = chkNotifyClient doesn't exist in IE.document (HTMLdocument).
If the Set ub... line, it means no elements with name = UpdateTask exist in IE.document.

It could be because the HTMLdocument is within a frame or iframe, however because I can't access this web site I can't give more specific help.

Using SendKeys and cursor positioning is unlikely to work reliably and consistently. Instead, manipulate/control the web page's HTML elements directly using the Microsoft HTML Object Library (HTMLdocument and all related classes) - search the web for examples, etc. One of my recent posts on another thread contained links to various references and tutorials. Sorry, but that's all the help I can give you.
 
Upvote 0

Forum statistics

Threads
1,214,405
Messages
6,119,315
Members
448,886
Latest member
GBCTeacher

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top