我如何通过多个变量,从一个Excel文件的批处理文件 [英] How do I pass multiple variables from an Excel file to a batch file

查看:319
本文介绍了我如何通过多个变量,从一个Excel文件的批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前能够使用从我的Excel文件传递一个参数传递给我的批处理文件如下:

I am currently able to pass one argument from my Excel file to my batch file using the following:

 filepath = "C:\Users\agaron\Desktop\batchmaster\batchfiles\batchfiletest.bat " & month

随后调用shell命令:

followed by calling a shell command:

    Call Shell(filepath, vbNormalFocus)

这工作正常。不过,我现在需要传递的不只是一个,而是18个参数,用上面的方法。我试着用串联的&放大器; 但现在看来,该批处理文件识别所有的参数作为一个单一

This works fine. However, I now require to pass not just one, but 18 parameters using the above method. I tried concatenating using the & but it appears that the batch file recognizes all the parameters as a single one.

如何能传递更多的参数,从Excel到批处理文件?

How can I pass more parameters from Excel to batch file?

推荐答案

Windows批处理文件获得通过空格分隔不同的参数。所以,如果您的批处理文件 batchfiletest.bat 是这样的:

Windows batch files get different parameters delimited by spaces. So if your batch file batchfiletest.bat is like:

echo off
echo %1
echo %2
echo %3
pause

那么下面VBA应该正常运行:

then the following VBA should run properly:

Sub testBatch()
 sMonth = Format(Now, "mmmm")
 sDay = Format(Now, "dd")
 sYear = Format(Now, "yyyy")
 filepath = "C:\Users\axel\batchfiletest.bat " & sMonth & " " & sDay & " " & sYear
 Shell filepath, vbNormalFocus
End Sub

这篇关于我如何通过多个变量,从一个Excel文件的批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆