Shell Command in VBA Execution

丶灬走出姿态 提交于 2021-02-11 12:42:33

问题


I'm trying to run two lines of commands using shell. I haven't been able to find a good source on how to actually execute shell in VBA. So far, I have been able to figure out how to open a specific directory.

Sub shellCMD()
     Shell ("cmd.exe /k CD\Users\n808037\Desktop\OTHER")
End Sub

This will at least lead me to the directory where I need to go. However, now that I've gotten to the directory I need to go, I need to execute a command after. That is

copy *.csv merged.csv

How do I do this in shell?


回答1:


Each Shell call runs in its own process, so you can't run separate commands by calling Shell consecutively. Generally, you'd want to either run multiple commands as a batch file or script if you were going to do a lot of processing. In this case, just specify the full path for copy. There's no need to change the working directory at all:

Shell "cmd.exe /k copy C:\Users\n808037\Desktop\OTHER\*.csv C:\Users\n808037\Desktop\OTHER\merged.csv"


来源:https://stackoverflow.com/questions/39756875/shell-command-in-vba-execution

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!