Page 1 of 2 12 LastLast
Results 1 to 10 of 11

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

This is a discussion on macro to navigate IE browser and click on checkbox and update button within the General Excel Discussion & Other Questions forums, part of the Question Forums category; Hi All, I have prepared a macro to open and navigate through one of the web page. I am got ...

  1. #1
    New Member AmitParekh's Avatar
    Join Date
    Jan 2013
    Posts
    21

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

    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!

  2. #2
    Board Regular
    Join Date
    Oct 2007
    Posts
    3,075

    Default Re: macro to navigate IE browser and click on checkbox and update button

    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.

  3. #3
    New Member AmitParekh's Avatar
    Join Date
    Jan 2013
    Posts
    21

    Default Re: macro to navigate IE browser and click on checkbox and update button

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

  4. #4
    New Member
    Join Date
    Jan 2013
    Posts
    1

    Default Re: macro to navigate IE browser and click on checkbox and update button

    thank you

  5. #5
    New Member AmitParekh's Avatar
    Join Date
    Jan 2013
    Posts
    21

    Default Re: macro to navigate IE browser and click on checkbox and update button

    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.

  6. #6
    Board Regular
    Join Date
    Oct 2007
    Posts
    3,075

    Default Re: macro to navigate IE browser and click on checkbox and update button

    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.

  7. #7
    New Member AmitParekh's Avatar
    Join Date
    Jan 2013
    Posts
    21

    Default Re: macro to navigate IE browser and click on checkbox and update button

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

  8. #8
    Board Regular
    Join Date
    Oct 2007
    Posts
    3,075

    Default Re: macro to navigate IE browser and click on checkbox and update button

    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.

  9. #9
    New Member AmitParekh's Avatar
    Join Date
    Jan 2013
    Posts
    21

    Default Re: macro to navigate IE browser and click on checkbox and update button

    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.

  10. #10
    Board Regular
    Join Date
    Oct 2007
    Posts
    3,075

    Default Re: macro to navigate IE browser and click on checkbox and update button

    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
    Quote Originally Posted by AmitParekh View Post
    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.

Page 1 of 2 12 LastLast

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


DMCA.com