使用 VBA 从 Word 发送 HTTP 请求
我正在尝试将 Word 文档中的数据发送到网页。我找到了一些代码,将其粘贴到新模块中并保存。当我运行它时,我收到“编译错误,用户定义的类型未定义”
我的代码:
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
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"
My code:
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
避免选择库的潜在替代方法是使用对象,即
A potential alternative to avoid having to select the library is to use an object i.e.
您需要在 VBA 项目中设置对 Microsoft WinHTTP Services 的引用(工具 -> 引用)。
它看起来像这样:
另外,您可以阅读有关 Microsoft WinHTTP 的更多信息服务版本 5.1 此处。
You need to set a reference to Microsoft WinHTTP Services in your VBA Project (Tools -> References).
Here's what it would look like:
Also, you can read more about the Microsoft WinHTTP Services, version 5.1 here.
您将需要更改您的引用(代码窗口中的工具=>引用)。查找
Microsoft WinHTTP Services 版本 5.1
(或更高版本)并勾选该框。如果您使用的是Vista和office 2007,您可能还需要先注册。以管理员身份打开命令窗口并粘贴:它应该显示它是否有效。
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:It should say if it works.