Results 1 to 3 of 3

Thread: [Excel] Can't Login via QueryTables to a Webpage (POST Method)

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    2

    Question [Excel] Can't Login via QueryTables to a Webpage (POST Method)

    Greetings,

    I'm having some problems with my current VBA script in Excel. The goal
    is to get a table from a website with the QueryTables function. Well,
    works fine so far. But to access the data which I need, I have to
    login (username/password).


    The login form runs with the POST method.


    Here is the current sourcecode


    Code:
    Sub Test() 
        Dim MyPost As String 
        Const MyUrl As String = "http://some-url" '<<<<<<<< Change this URL. 
        Const PostUser As String = "user=Username" 'Change user name here 
        Const PostPassword As String = "&pass=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
    Things you need to change to test this code:
    - URL: Just find a webpage with a login form, and copy the URL in the
    proper string.
    - Username-Field: Take a look at the sourcecode of the webpage. Look
    for the input fields name, and put it before the username
    - Password-Field: Same with username-field.


    Things I checked so far:
    - Correct name of the input boxes
    - Correct URL


    Now, why won't it just work? Do you guys have any ideas?


    PS: Running Vista and Excel 2007


    --
    pmw2600

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [Excel] Can't Login via QueryTables to a Webpage (POST Method)

    Welcome to the forums.

    What happens when you run it? Are you getting an error? If so, what?

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    2

    Re: [Excel] Can't Login via QueryTables to a Webpage (POST Method)

    Thanks!

    Well, there is no error actually. It just doesn't login. I can see that if I look at the return string of the QueryTable object.

    --
    pmw2600

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