tags:

views:

60

answers:

2

I'm trying to send data from a word document to a web page. Ive found some code and pasted it into a new module and saved it, but when I run it I get "compile error, user defined type not defined"

Sub http()

  Dim MyRequest As New WinHttpRequest

    MyRequest.Open "GET", _
    "http://www.google.com"

    ' Send Request.
    MyRequest.Send

    'And we get this response
    MsgBox MyRequest.ResponseText

End Sub
A: 

You will need to change your references (Tools=>References in the code window). Look for Microsoft WinHTTP Services, version 5.1 (or newer) and tick the box. If you are using Vista and office 2007, you may also need to register it first. Open a command window as administrartor and paste:

>regsvr32.exe "c:\windows\system32\winhttp.dll"

It should say if it works.

Remou
+1  A: 

A potential alternative to avoid having to select the library is to use an object i.e.

Sub http() Dim MyRequest As Object

Set MyRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
MyRequest.Open "GET", _
"http://www.google.com"

' Send Request.
MyRequest.Send

'And we get this response
MsgBox MyRequest.ResponseText

End Sub

Chris

Crispy
This worked for me, thanks
Saul