shahin
Active Member
I've created a macro to scrape proxies from a free proxy site. The macro is capable fetching the proxies when I use it within a subroutine. However, my intention is to print the proxy list within this subroutine "PrintProxies" via the function "GenerateProxy". I don't understand how to return the collection of result from that function so that I can print it within the subroutine.
When I run the above macro, I see this error `object required` pointing at this line `Set iCol = GenerateProxy`.
PS There is a cross-post https://stackoverflow.com/questions/65049118/cant-print-the-result-of-a-function-within-a-sub in place.
EDIT: The problem appears to have been fixed. Turn out that there was a typo which was causing that error.
Code:
Function GenerateProxy() As Collection
Dim oHttp As New ServerXMLHTTP60, Html As New HTMLDocument
Dim iCol As New Collection, pIP$, pPort$, elem As Object
With oHttp
.Open "GET", "https://www.us-proxy.org/", True
.send
While .readyState < 4: DoEvents: Wend
Html.body.innerHTML = .responseText
For Each elem In Html.getElementsByTagName("tbody")(0).getElementsByTagName("tr")
If InStr(elem.innerText, "yes") > 0 Then
pIP = elem.getElementsByTagName("td")(0).innerText
pPort = elem.getElementsByTagName("td")(1).innerText
Debug.Print pIP & ":" & pPort
iCol.Add pIP & ":" & pPort
End If
Next elem
End With
Set GenerateProxy = iCol
End Function
Sub PrintProxies()
Dim iCol As Collection, col As Variant
Set iCol = GenerateProxy
For Each col In iCol
Debug.Print col
Next col
End Sub
When I run the above macro, I see this error `object required` pointing at this line `Set iCol = GenerateProxy`.
PS There is a cross-post https://stackoverflow.com/questions/65049118/cant-print-the-result-of-a-function-within-a-sub in place.
EDIT: The problem appears to have been fixed. Turn out that there was a typo which was causing that error.
Last edited: