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.

VBA code to Log -in to a website to download the data

Discussion in 'VBA Macros' started by Balajisx, May 18, 2017.

  1. Balajisx

    Balajisx Member

    Messages:
    40
    Hi Team,

    Can I get a VBA code to auto log-in to a secure webpage using the login credentials and download the data from the web application ?

    Thanks in advance :)
  2. Belleke

    Belleke Member

    Messages:
    102
    Try
    Code (vb):
    Sub Belleke()
        With CreateObject("InternetExplorer.Application")
        .Navigate "http://enter web page here"
        Do Until .ReadyState = 4
          DoEvents
        Loop
        DoEvents
     
        ie.Document.Forms(0).all("User").Value = "Balajisx"
        ie.Document.Forms(0).all("Password").Value = "password"
        ie.Document.Forms(0).submit
      End With
    End Sub
    Balajisx likes this.
  3. Balajisx

    Balajisx Member

    Messages:
    40
    Thank you Belleke. I tried your code however I got an error stating "Automaton error" The interface is unknown. I did a slight modification in the code.
    Set ie = New InternetExplorerMedium
    ie.Visible = True
    ie.Navigate ("https://xxx.xyz/EDG/")
    however when it comes to submit i am not able to log in. Please assist.
  4. Chihiro

    Chihiro Well-Known Member

    Messages:
    3,150
    There's no one size fits all code for Web interaction/scraping.

    You'll need to find the type of authorization required by the web site (such as OAuth2) and write code accordingly.

    If using IE automation, you'll need to find out element/form control names that the site uses.
    Balajisx and shahin like this.
  5. Balajisx

    Balajisx Member

    Messages:
    40
    Hi Chihiro, please find the element below. I believe the name is submit.However When I write a code by using these name or class or type or value the page is not getting loaded. Please advise
    upload_2017-5-18_19-4-48.png
  6. Chihiro

    Chihiro Well-Known Member

    Messages:
    3,150
    Right, but what's the element for User/Name and Password?
  7. Balajisx

    Balajisx Member

    Messages:
    40
    for user name
    input name="ctl00$MainContent$txtUserId" type="text" id="ctl00_MainContent_txtUserId" title="Enter User Name" autocomplete="off" style="width: 97%" /></p>

    For Password

    <input name="ctl00$MainContent$txtPwd" type="password" id="ctl00_MainContent_txtPwd" title="Enter Password" autocomplete="off" style="width: 97%" /></p>
  8. Chihiro

    Chihiro Well-Known Member

    Messages:
    3,150
    Replace "User" & "Password" in code with "ctl00$MainContent$txtUserId" and "ctl00$MainContent$txtPwd" respectively.
    Balajisx likes this.
  9. Balajisx

    Balajisx Member

    Messages:
    40
    I did chihiro. but still it does not allow me to go to the home page. However I given a break before submit in my coding and when I press login button in IE manually I am able to do it. I m stucked here :-(
  10. shahin

    shahin Member

    Messages:
    245
    Hi Balajisx! It's better to reveal the link or at least provide with one similar to what you are trying with at this moment to get a quicker and exact answer.
  11. Balajisx

    Balajisx Member

    Messages:
    40
    Hi Shahin, Since it is an confidential information, I am in a suitation not to reveal the link. Also I do have the similar one :-(

Share This Page