简体   繁体   English

如何编写VBA Shell脚本以在可变文件上运行PHP脚本

[英]How to Write a VBA Shell Script to Run a PHP Script on Variable Files

I'm trying to write a shell script that will run a PHP script on a number of files at once (this requires using an exe file and a php file on a json file). 我正在尝试编写一个将同时在多个文件上运行PHP脚本的shell脚本(这需要在json文件上使用exe文件和php文件)。 The json file is the only one that is variable in this situation. json文件是在这种情况下唯一可变的文件。

If I were using the command prompt manually, here's the command I would need to input to achieve the desired result- 如果我是手动使用命令提示符,则需要输入以下命令才能获得所需的结果-

C:/Users/myusername/Desktop/XAMPP/php/php.exe transcript.php transcribedfile.json

Cell G2 of my worksheet contains the json filename, so that's why I've activated it in the second line. 我的工作表的单元格G2包含json文件名,因此这就是我在第二行中将其激活的原因。 Once I can get the shell script to work I will code in a loop that will cycle through all values in the G column, beginning with G2, until the ActiveCell value is "". 一旦使Shell脚本正常工作,我将在一个循环中进行编码,该循环将循环遍历G列中的所有值,从G2开始,直到ActiveCell值为“”。

Here's what I've tried- 这是我尝试过的-

Sub Shell()
Range("G2").Activate
Dim strProgramName As String
Dim strArgument As String

strProgramName = "C:\Users\myusername\Desktop\XAMPP\php\php.exe transcript.php " & ActiveCell.Value
strArgument = "/G"

Call Shell("""" & strProgramName & """ """ & strArgument & """", vbNormalFocus)

End Sub

When I run the sub I get a "File Not Found" error. 当我运行子程序时,出现“找不到文件”错误。 I tested strProgramName and found that I could get php.exe to run if I cut the code off at that point, but I would need it to recognize the whole string. 我测试了strProgramName,发现如果在那时将代码切断,我可以使php.exe运行,但是我需要它来识别整个字符串。

Any ideas would be welcome. 任何想法都将受到欢迎。 Thank you in advance. 先感谢您。

Here's how I'd do this: 这是我的处理方式:

Const PHP_PATH As String = "C:\Users\myusername\Desktop\XAMPP\php\"
Dim strProg As Variant

strProg = """{pth}php.exe"" ""{pth}transcript.php"" ""{pth}" & _
          Range("G2").Value & """ \G"

strProg = Replace(strProg, "{pth}", PHP_PATH)
Debug.Print strProg '<< pass this to Shell

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM