如何使用 VBA 发送要在 Facebook Graph API 调用中用作 PHP 变量的单元格内容?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15099588/
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
How do I use VBA to send cell contents to be used as a PHP variable in a Facebook Graph API call?
提问by Jeremy Friedman
I'm working on building a local php page to output the public Company info from Facebook in XML with help from a friend and I am going to create a VBA macro to webcrawl to that page and download the information into my workbook in Excel. However, the input for the company name must be from a cell on the spreadsheet and I don't know how to pass this into the request I am sending to the Graph API besides writing that straight into the PHP file. How do I make VBA pass the value from the spreadsheet cell (eg. A1=Hilton) to PHP to replace the hard-coded company name so that I can use this for any company?
我正在构建一个本地 php 页面,以便在朋友的帮助下以 XML 格式从 Facebook 输出公共公司信息,我将创建一个 VBA 宏以通过网络抓取到该页面并将信息下载到我的 Excel 工作簿中。但是,公司名称的输入必须来自电子表格上的一个单元格,除了直接将其写入 PHP 文件之外,我不知道如何将其传递到我发送到 Graph API 的请求中。如何让 VBA 将电子表格单元格(例如 A1=Hilton)中的值传递给 PHP 以替换硬编码的公司名称,以便我可以将其用于任何公司?
Clarification of Requirements:
要求的澄清:
- VBA Reads company name from cell A1
- VBA sends company name as variable to PHP
- PHP post to Graph API using the company name sent from VBA
- VBA Macro crawls local PHP page and downloads the XML output into workbook
- VBA 从单元格 A1 中读取公司名称
- VBA 将公司名称作为变量发送给 PHP
- PHP 使用从 VBA 发送的公司名称发布到 Graph API
- VBA 宏抓取本地 PHP 页面并将 XML 输出下载到工作簿中
回答by Sam Plus Plus
You could use a VBA macro like I created below. In my example I made the macro tied to a button click
您可以使用我在下面创建的 VBA 宏。在我的示例中,我将宏绑定到按钮单击
Sub Button1_Click()
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
URL = "http://www.yourdomain.com/page.php?variable=" & ActiveWorkbook.Worksheets(1).Range("A1").Value
objHTTP.Open "GET", URL, False
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.send ("")
End Sub
Your PHP script on your server would look like
您服务器上的 PHP 脚本看起来像
<?php
$excelCellA1Value = $_GET["variable"];
//Work magic here such as posting to Facebook API
//TO DO: Profit!
?>