VBA... Import data not working

cicada

Board Regular
Joined
Jan 10, 2010
Messages
79
Hi all I am having issues with a code i used to run but now returrns strange data. i am using the following code to open a list of links listed in worksheet 1 in worksheet 2. i can't find the original code that i was using and i'm not sure that this is correct


Code:
Sub ImportData()
   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


now when i run this macro instead of getting the contents of each listed link in sheet 2 all i get is this for each link
(note i am in france atm)

Internet Internet opérationnel
Téléphonie Téléphonie active
Télévision Télévision connectée
Version : ########### (censored for public)
Adresse MAC : ##########(as above)
Adresse IP : ##########(as above)
Profil d'accès : neufbox ADSL

i have no idea why this occurring. strange.

any help would be greatly appreciated

thanks
Dan
p.s as i said there could be something crucial missing from this code. as i am a far cry from being vba proficient i have no idea what.

:confused:
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
ok so this is the new code whilst im no getting that weird ip stuff anymore it is still just displaying the login page in sheet 2. this is the new code


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

Does anyone have any clues as to why this is not working. i used to be able to get this to work with no glitch. I remember it used to work by simply just manually logging n through my browser before running the code. now nada.
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,181
Members
452,893
Latest member
denay

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