1. Welcome to Chandoo.org Forums. Short message for you

    Hi Guest,

    Thanks for joining Chandoo.org forums. We are here to make you awesome in Excel. Before you post your first question, please read this short introduction guide. When posting or responding to questions please remember our values at Chandoo.org are: Humility, Passion, Fun, Awesomeness, Simplicity, Sharing Remember that we have people here for whom English is not there first language and we need to allow for this in our dealings.

    Yours,
    Chandoo
  2. Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  3. When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Web VBA issue

Discussion in 'VBA Macros' started by sms2luv, Jul 14, 2017 at 4:37 PM.

  1. sms2luv

    sms2luv Member

    Messages:
    88
    Hi, I am making a VBA code to open a site to get some data and need help.

    Its a intranet site
    The site has a certifical error, so every time we open the site, we have to click on proceed to site anyway.

    The site then have a agree button for terms and conditions.

    Code I used is as below.
    Ms internet controls and ms HTML references are added.
    Code (vb):

    Dim ie as new shwdoc.internetexplorer
    Dim htmldoc as mshtml.htmldocument
    Dim htmlinput as mshtml.ihtmlelement

    ie.visible = true
    is.navigate "site name"

    Do while readystate <> readystate complete
    Loop

    Set htmldoc = ie.document

    'For clicking proceed to site
    Set htmlinput = htmldoc.getelementbyid("override")
    htmlinput.Click

    'For clicking I Agree
    Set htmlinput = htmldoc.getelementbyid("btnagree")
    htmlinput.Click

    End sub
     
    When I run this, a new ie opens and I am directed to I Agree page, which means proceed to site is working.
    But for some reason its not able to click on I Agree

    Please help
  2. sms2luv

    sms2luv Member

    Messages:
    88
  3. Chihiro

    Chihiro Well-Known Member

    Messages:
    3,316
    From what you described. After below operation...
    Code (vb):
    Set htmlinput = htmldoc.getelementbyid("override")
    htmlinput.Click
     
    A new IE opens. Correct?

    That means you need to set new instance of IE as htmldoc before you can use it. Or you are just using previous page and code won't find "btnAgree" in the doc.
  4. sms2luv

    sms2luv Member

    Messages:
    88
    Sorry to say, but override is a hyperlink in the page and it says proceed to the site anyway.
    Image attached as sample.

    When I click on proceed anyway, I get I agree page.
    This does not open a new page.

    Attached Files:

  5. Chihiro

    Chihiro Well-Known Member

    Messages:
    3,316
    Hmm? When you print entire content of htmldoc, "Before" you click on override. What do you get? And what do you get after you click on override?

    I ask, since the php/html you posted does not have elementid "override" in it.

    Edit: Also, I'd recommend installing certificate (get IT to do it for you if needed) or fix it by adjusting computer time and/or by deleting the site from Untrusted Publishers
    Last edited: Jul 14, 2017 at 5:59 PM
  6. sms2luv

    sms2luv Member

    Messages:
    88
    As soon as ie opens, I get a message that the site has a certificate error (example image attached earlier).
    After 1 sec I get a page to agree to the terms and after that nothing happens.

    I used ie to inspect the page, and when I highlighted the "proceed to site anyway" I got an id named override.
  7. Chihiro

    Chihiro Well-Known Member

    Messages:
    3,316
    I get that. That's not the issue.

    You are setting htmldoc = ie.document before you click override. Yes?

    You then click on override. Then it loads the page. Now, htmldoc is before the click, so isn't updated to newly loaded page.

    You have to wait for new page to load, then reset the htmldoc.
  8. sms2luv

    sms2luv Member

    Messages:
    88
    Thanks a lot for faster response.
    I tried the below thing, still did not work.
    Entire code was same, but I added
    Code (vb):
    Dowhile readystate <> readystate complete
    Loop
    After clicking on override.
    I mean above I agree button to reload the page completely.
  9. Chihiro

    Chihiro Well-Known Member

    Messages:
    3,316
    But then you need to Set htmldoc = ie.document after clicking override as well. Since the content has changed after the click.
  10. sms2luv

    sms2luv Member

    Messages:
    88
    I tried the below code, but did not work, please help
    Error is Run time error 91
    Object variable or with block variable not set
    Htmlin2.click gets highlighted for debug

    Code (vb):


    Option Explicit


    Sub test()

    Dim ie As New SHDocVw.InternetExplorer

    Dim htmldoc As MSHTML.HTMLDocument

    Dim htmlin As MSHTML.IHTMLElement

    Dim htmldoc2 As MSHTML.HTMLDocument

    Dim htmlin2 As MSHTML.IHTMLElement


    ie.Visible = True

    ie.navigate "Site Name"


    Do While ie.readyState <> READYSTATE_COMPLETE

    Loop



    Set htmldoc = ie.document

    Set htmlin = htmldoc.getElementById("overridelink")

    htmlin.Click


    Do While ie.readyState <> READYSTATE_COMPLETE

    Loop



    Set htmldoc2 = ie.document

    Set htmlin2 = htmldoc.getElementById("btnAgree")

    htmlin2.Click


    End Sub

     
    Pasting fresh website code again, might be it had changed.
    https://www.pastiebin.com/596a37c2dc23f
  11. sms2luv

    sms2luv Member

    Messages:
    88
    Please help me team
  12. Chihiro

    Chihiro Well-Known Member

    Messages:
    3,316
    When you print htmldoc2 to text file what do you get?

Share This Page