从 Word 使用 VBA 发送 HTTP 请求 [英] Sending HTTP requests with VBA from Word

查看:56
本文介绍了从 Word 使用 VBA 发送 HTTP 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将数据从 Word 文档发送到网页.我找到了一些代码,将其粘贴到一个新模块中并保存.当我运行它时,我收到编译错误,未定义用户定义的类型"

I am trying to send data from a Word document to a web page. I have found some code, pasted it into a new module, and saved it. 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 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

这篇关于从 Word 使用 VBA 发送 HTTP 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆