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



## AmitParekh (Jan 18, 2013)

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!


----------



## John_w (Jan 19, 2013)

For the checkbox, try something like:

```
Dim cb As Object
Set cb = IE.document.getElementById("chkNotifyClient")
cb.Checked = False
```
For the button:

```
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.


----------



## AmitParekh (Jan 21, 2013)

I will try this let you know. Thanks for you help!


----------



## rsawant23 (Jan 24, 2013)

thank you


----------



## AmitParekh (Jan 28, 2013)

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.


----------



## John_w (Jan 28, 2013)

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.


----------



## AmitParekh (Jan 28, 2013)

yes John, I have defined the IE and added the Microsoft internet controls reference also. But still its giving me the same error message.


----------



## John_w (Jan 28, 2013)

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.


----------



## AmitParekh (Jan 28, 2013)

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
> ...



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.


----------



## John_w (Jan 28, 2013)

```
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
```



AmitParekh said:


> 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.


----------



## AmitParekh (Jan 18, 2013)

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!


----------



## AmitParekh (Jan 28, 2013)

Yes, I have to replace those tab codes. Need to gain more knowledge on this. Thanks for all your help. I will go through those web help links...


----------

