Posts Tagged ‘httprequest’

Grabbing Data from Web using VBScript/VBA

Tuesday, November 25th, 2008

You can grab data from web URL, here is 2 methods we can use.

1. Using IE Instance
The first method using IE instance
pros:

  • No need to install
  • You can see the progress by uncomment set visible line

cons:

  • IE doesnt have method to let you wait until finish, so you must check in a loop
  • IE takes more memory than other methods
Function IEGetRequest(URL)
  'Create IE Instance
  Dim IeInstance

  Set IeInstance = CreateObject("InternetExplorer.Application")

  'Uncomment the next line to see IE window
  'IeInstance.Visible = True

  IeInstance.Navigate URL

  Do While IeInstance.Busy
    Wait 1, "Waiting " & URL
  Loop

  'Get the response
  On Error Resume Next
  IEGetRequest = IeInstance.Document.Body.innerHTML
  IeInstance.Quit
End Function

Sub Wait(sec, msg)
  On Error Resume Next
  Dim Shell
  If IsEmpty(Shell) Then
    Set Shell = CreateObject("WScript.Shell")
  End If
  Shell.Popup msg, sec, "", 64
End Sub

' Test the function
MsgBox IEGetRequest("http://www.yahoo.com/")

(more…)