View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Matthew Herbert[_3_] Matthew Herbert[_3_] is offline
external usenet poster
 
Posts: 149
Default Can a macro read a list and insert the names into a web address?

Darren,

I put the code together rather quickly; it's not tested, but it should at
least give you an idea of the syntax you can use to piece together what you
need. (You'll have to debug the code, and using F8 (i.e. Step Into) is a
good way to debug the code. Also, I used only one parameter for
..TextToColumns, which is a very poor assumption). The code assumes that the
return text is separated by a line feed characer (i.e.
vbLf/Chr(10)/CHAR(10)), the text is delimited by a comma, the names are
listed in worksheet 1, and the output is listed in worksheet 2.

Best,

Matthew Herbert

Sub CustomData()
Dim rngCell As Range
Dim rngList As Range
Dim strRes As String
Dim varArr As Variant
Dim rngOut As Range
Dim rngPaste As Range
Dim rngData As Range
Dim lngCnt As Long
Const c_intOffset As Integer = 39
Const c_strBaseURL As String =
"http://hiscore.runescape.com/index_lite.ws?player="

With ThisWorkbook
Set rngList = .Worksheets(1).Range("B3")
Set rngList = Range(rngList, rngList.End(xlDown))
Set rngOut = .Worksheets(2).Range("B1")
End With

lngCnt = 0
For Each rngCell In rngList.Cells
strRes = GetXMLHTTP(c_strBaseURL & rngCell.Value)
If strRes < "" Then
varArr = Split(strRes, vbLf)

Set rngPaste = rngOut.Offset(lngCnt * c_intOffset, 0)

Set rngData = Range(rngPaste, _
rngPaste.Offset(UBound(varArr), 0))

rngData.Value = Application.Transpose(varArr)

rngData.TextToColumns Comma:=True

lngCnt = lngCnt + 1
End If
Next rngCell
End Sub

Function GetXMLHTTP(strURL As String) As String

Dim objXMLHTTP As Object
Dim strText As String

Set objXMLHTTP = CreateObject("Microsoft.XMLHTTP")

If strURL = "" Then
GetXMLHTTP = ""
Exit Function
End If

With objXMLHTTP
.Open "GET", strURL, False
.Send
strText = .responseText
End With

If objXMLHTTP.statusText = "OK" Then
GetXMLHTTP = strText
Else
GetXMLHTTP = ""
End If

End Function

"Darren" wrote:

I want to know if a macro can read a list of names (can be from 10 - 100
long) from 1 sheet and copy each name individually into a web address. Then
place the results onto another sheet at pre determined places.
Heres what I have:
On Sheet xp from cell B3 is the list of names
b
3 Thrasherfan
4 Mummybear58
3 Galadriel107

I want to read each name, 1 at a time and place them into:
http://hiscore.runescape.com/index_l...player=*Insert name here*

Then place that information onto:\
Sheet Team 1, cell B1 for 1st name
Sheet Team 1, cell B41 for 2nd name
Adding 40 cells for each consecutive name. So name 3 would be B81 etc.

Is this possible, and if so, how would I go about it?