Pulling web data

SandsB

Well-known Member
Joined
Feb 13, 2007
Messages
681
Office Version
  1. 365
Platform
  1. Windows
I use the macro below to pull data from 4 tables on a web page. D12 contains the username I'm looking for and the macro pulls all of the data related to that user and pastes it into the same sheet starting at C30.

I need another version of this macro that will take a list of usernames and enter the web data on a new tab for each of the users in the list. So if A5 = JoeB123, the macro will go to the web page, get the data in the 4 tables, and then paste it into a new tab named JorB123 in the same file. Then if A6 = BobM123, it'll do the same thing for him and for as many usernames I have in my list after that.

I'm not smart enough to figure this out.

-------
Sub NameME()
'
Dim UserName As String
UserName = ActiveSheet.Range("D12")
Range("D30").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://userbase.myco.com/cgi-bin/userwho.pl?id=" & UserName, Destination:= _
Range("$C$30"))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "8,9,10,11"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
assuming you have user names in cells a5 to a a22
try like this
Code:
Sub NameME()
'
Dim UserName As String
For Each cell In Range("a5:a22")
    UserName = cell.Value
    Set newsht = Sheets.Add
    newsht.Name = username
'    Range("D30").Select
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;http://userbase.myco.com/cgi-bin/userwho.pl?id=" & UserName, Destination:= _
        Range(newsht.Name & "!$C$30"))
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = False
        .RefreshPeriod = 0
        .WebSelectionType = xlSpecifiedTables
        .WebFormatting = xlWebFormattingNone
        .WebTables = "8,9,10,11"
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
Next
End Sub
i have not tested this at all
 
Upvote 0

Forum statistics

Threads
1,203,174
Messages
6,053,918
Members
444,694
Latest member
JacquiDaly

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