vba 无需打开网页即可在 Excel 2010 中调用 URL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16397251/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Call a URL in Excel 2010 without opening the webpage
提问by arok
My Excel sheet consists of mobile numbers.
我的 Excel 工作表由手机号码组成。
I want to pass each number to a URL and perform a certain code on my server.
我想将每个数字传递给一个 URL 并在我的服务器上执行某个代码。
I have created a button and have wrote the below code:
我创建了一个按钮并编写了以下代码:
Private Sub CommandButton1_Click()
strURL = "http://xxxxxxx.com/myAPI.php?mobilenumber=" _
& ActiveCell.Value
Call Sheets("Sheet1").Navigate(strURL)
End Sub
But unfortunately it is not working.
但不幸的是它不起作用。
Please not that I don't want to redirect to http://xxxxxxx.com/myAPI.php
just calling it and pass the mobilenumber
to it.
请不要说我不想重定向到http://xxxxxxx.com/myAPI.php
只是调用它并将其传递mobilenumber
给它。
Thanks
谢谢
回答by Santosh
You can achieve it using XMLHttp. Below is sample code.
您可以使用 XMLHttp 来实现它。下面是示例代码。
XMLHttpRequestobject is used to exchange data with a server behind the scenes
XMLHttpRequest对象用于在后台与服务器交换数据
Sub SendSms()
Dim URL As String
URL = "http://xxxxxxx.com/myAPI.php?mobilenumber=" & ActiveCell.Value
Dim xml As Object
Set xml = CreateObject("MSXML2.XMLHTTP")
xml.Open "GET", URL, False
xml.Send
End Sub