Password automation import data VBA

cicada

Board Regular
Joined
Jan 10, 2010
Messages
79
I previously posted a similar question and didn't recieve a reply perhaps it demanded to much involvement. So instead of bumping I will restructure my question. I have a list of URL's in sheet 1, I am trying to have the contents of those urls imported to sheet 2. The loop part of the code works well fif i have 60 urls in sheet 1 i get (and here is the problem) 60 login pages of that website in sheet 2. Can anyone see what i am doing wrong. I think it is something simple but i dont really know what im doing when it comes to VBA. Maybe i've repeated some stuff in teh code
thanks for your help
Dan


Code:
Sub Login_WebQuery()
Dim MyPost As String
Const MyUrl As String = "http://www.greyhound-data.com/login.htm?z=UFFvLs"
Const PostUser As String = "login=enter my user name here"
Const PostPassword As String = "&pass= enter my password here"
    
MyPost = PostUser & PostPassword
       
   With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;http://www.greyhound-data.com/login.htm?z=UFFvLs", Destination:=Range( _
        "$AZ$1"))
        .Name = "login.htm?z=UFFvLs"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False

        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlEntirePage
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
    Sheets(2).Activate
    i = 1
    Do Until Sheets(1).Cells(i, 1) = ""
        myquery = Sheets(1).Cells(i, 1)
        Sheets(2).Cells(1, 1) = myquery
        myrow = Sheets(2).UsedRange.Rows.Count + 1
        Do
            myrow = myrow - 1
        Loop Until Sheets(2).Cells(myrow, 1) <> ""
        myrow = myrow + 1
        With Sheets(2).QueryTables.Add(Connection:= _
            "URL;" & myquery, Destination:=Sheets(2).Cells(myrow, 1))
            .BackgroundQuery = True
            .TablesOnlyFromHTML = True
            .Refresh BackgroundQuery:=False
            .SaveData = True
        End With
i = i + 1
Loop
End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I see that in the beginning of your code, a string containing login and password is defined, but it seems to me it is never used in the rest of the code. That would explain why all your URL's end up on a password screen which is what gets captured.

I have no idea how to include the login info in the URL's you have, you should check what an URL with login and password looks like, and then someone here might assist in adapting the code...
 
Upvote 0
Thanks for the reply,
I would have thought that once logged in (which is the first part of my code) would allow the other links all of the same website to be accessed. some time ago i used to run something like this on the same site without a hitch before that i used to just log in manually via the browser and the run the code without the password part. unfortunately i lost that code and cant seem to replicate what i was doing even the manual logging in part doesnt seem to work. at a loss really. lastly i remember getting the successful code from somewhere on this forum (possible it was another) but cant find it. please help someone.

Regards
Dan
 
Upvote 0

Forum statistics

Threads
1,224,557
Messages
6,179,504
Members
452,917
Latest member
MrsMSalt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top