MS Word VBA,尝试使用来自http调用的数据填充组合框
我正在使用以下代码填充 Word 2003 中的组合框。
Private Sub UserForm_Initialize()
ComboBox1.List = Array("Red", "Green", "Yellow", "Blue")
End Sub
我想要做的是通过 http 调用动态获取数据。这个其他函数似乎可以通过 http
Dim MyRequest As Object
Set MyRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
MyRequest.Open "GET", _
"http://localhost:8500/test7.htm"
' Send Request.
MyRequest.Send
'And we get this response
MsgBox MyRequest.ResponseText
test7.htm 获取数据,只包含
"Red", "Green", "Yellow", "Blue"
我希望将两者结合起来,但下面不起作用
Private Sub UserForm_Initialize()
Dim MyRequest As Object
Set MyRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
MyRequest.Open "GET", _
"http://localhost:8500/test7.htm"
' Send Request.
MyRequest.Send
ComboBox1.List = Array(MyRequest.ResponseText)
End Sub
对 VBA 菜鸟的任何帮助表示赞赏
I'm using the following code to populate a combobox in Word 2003.
Private Sub UserForm_Initialize()
ComboBox1.List = Array("Red", "Green", "Yellow", "Blue")
End Sub
What I would like to do is get the data dynamically via an http call. This other function seems to work to get data via http
Dim MyRequest As Object
Set MyRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
MyRequest.Open "GET", _
"http://localhost:8500/test7.htm"
' Send Request.
MyRequest.Send
'And we get this response
MsgBox MyRequest.ResponseText
test7.htm just contains
"Red", "Green", "Yellow", "Blue"
I was hoping to combine the two but below doesn't work
Private Sub UserForm_Initialize()
Dim MyRequest As Object
Set MyRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
MyRequest.Open "GET", _
"http://localhost:8500/test7.htm"
' Send Request.
MyRequest.Send
ComboBox1.List = Array(MyRequest.ResponseText)
End Sub
Any help for a VBA noob appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
响应文本应该是一个简单的逗号分隔字符串,类似于
因此,您可以使用以下方法来填充组合框:
要调用该方法,您可以使用以下句子。
The response text should be a simple comma separated string, something like
Thus you can use the following method for populating the ComboBox:
For calling the method you can use the following sentence.