Results 1 to 5 of 5

Thread: [RESOLVED] [Excel 2010] Web quries and login details

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2010
    Location
    Victoria, Australia
    Posts
    14

    Resolved [RESOLVED] [Excel 2010] Web quries and login details

    Hi,

    I am looking into downloading stock information from a website (netwealth.com.au) that requires login details to get the information which I then would like to import into excel to be manipulated.

    I have done some digging and have found a number of examples but I cant get any of them to work. I can see that this could be quite a difficult ask but any help is greatly appreciated!!!

    I have tried using the inbuilt web data function and tried ticking "remember user name" etc. but no luck, so now i'm looking to VBA to help solve this problem.

    Thanks in advance,

    Ash.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [Excel 2010] Web quries and login details

    show the code variations, you have tried
    also the link to the web page, if it is available
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2010
    Location
    Victoria, Australia
    Posts
    14

    Re: [Excel 2010] Web quries and login details

    Well when I attempt to got to the page that I want to get the info from it will redirect me to a login page so below are both the login page and the desired page (The first address listed below)

    https://www.sharetrading.netwealth.c...?stockCode=MOC

    https://www.sharetrading.netwealth.c...nRequired.aspx

    Eventually the code will lookup a stock code in a cell that will then be placed into the address (where MOC is) and then download the data for that company... but at this stage all I am trying to figure out is to actually login to the site via VBA.

    This is the code that I think is the most relevant (found here: http://www.vbforums.com/showthread.p...ght=login+form)

    Code:
    Sub Test()
        Dim MyPost As String
        Const MyUrl As String = "https://www.sharetrading.netwealth.com.au/LoginRequired.aspx"
        Const PostUser As String = "ctl00$LoginControl1$txtLogin=Username" 'Change user name here
        Const PostPassword As String = "ctl00$LoginControl1$txtPassword=Password" 'Change password here
    
        MyPost = PostUser & PostPassword
    
        With ActiveSheet.QueryTables.Add(Connection:= _
            "URL;" & MyUrl, Destination:=Cells(1, 1))
            .PostText = MyPost
            .BackgroundQuery = True
            .TablesOnlyFromHTML = True
            .Refresh BackgroundQuery:=False
            .SaveData = True
        End With
    End Sub
    I have attempted to modify it to the login address and page source but have had no luck so far.

    Thanks for the help,

    Ash.

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [Excel 2010] Web quries and login details

    i have not tried using a query table but have posted a few examples using an instance of internet explorer, to populate a range from web tables after logging in see the thread below
    http://www.vbforums.com/showthread.p...ghlight=iframe also i posted another example recently (about 2 weeks ago), in another thread, also in this forum
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2010
    Location
    Victoria, Australia
    Posts
    14

    Re: [Excel 2010] Web quries and login details


Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width