How to get a webpage data without navigating to it. VBA

Bruj used Ask the Experts™
I came across a technique a few years back that allowed me to grab data from a webpage without navigating to that page. I was actually very simple, but I forgot how to did it.
I believe it was just the Excel internet or html libraries, but it may have been one of windows APIs.

I "think" it was something like a "get" command.

I have about 4000 pages I need to verify nightly and would really like to speed things up.

I did this in Widows 7 and probably IE9. I currently run Win 10 with Edge. Have not done much webstuff with Edge.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Course Leader & Managing Director
Hi Bruce

I don't know what URL you want to get from and what you want to actually get.  However this exhibit shows you how to use WinHTTP (late bound - so no reference checking required).  And it is not browser specific.

Sub Example()
    Debug.Print GetSource("")
End Sub

Function GetSource(ByVal strURL As String) As String
    Dim objWinHttp As Object 'WinHttpRequest
    Set objWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")

    Call objWinHttp.Open("GET", strURL)
    Call objWinHttp.Send
    GetSource = objWinHttp.ResponseText
End Function

Open in new window


Thank you VERY VERY much! Works like a charm and will same me hours of computer running each day!
Now I just need to re-write my parsing functions!
I am really surprised this method is not used more! It is so much cleaner, faster and easier!
I was really floored when I came across it the first time, and was using it on alot of code (but that was a few years back!)
I just have not don't that type of web automation for a long time.

Very complete and was there right at the right time (think it was less than 15 min!)
Jon von der HeydenCourse Leader & Managing Director

You're most welcome Bruce.  As the saying goes, "there's more than one way to skin a cat".  I only elected to use WinHTTP out of familiarity.  Best of luck!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial