使用Excel宏执行命令并关闭cmd窗口 [英] Execute command with Excel macro and close cmd window

查看:98
本文介绍了使用Excel宏执行命令并关闭cmd窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我现在正在尝试的内容:

  Sub del_BJSFM_files()调用Shell("cmd.exe/S/K"&"cd/d C:\ UTAS-SA& del/f/s/q BJSFM> nul",vbNormalFocus)结束子 

问题在于命令窗口保持打开状态.

我尝试删除"/K",但是命令无法正确执行.

解决方案

/C -运行Command,然后终止

/K -运行命令,然后返回到CMD提示符.这对于测试,检查变量很有用

来源-https://ss64.com/nt/cmd.html

Here is what I'm trying right now:

Sub del_BJSFM_files()

Call Shell("cmd.exe /S /K" & "cd /d C:\UTAS-SA && del /f/s/q BJSFM > nul", vbNormalFocus)

End Sub

The problem is that the command window stays open.

I tried removing the "/K" but then the command doesn't execute properly.

解决方案

/C - Run Command and then terminate

/K - Run Command and then return to the CMD prompt. This is useful for testing, to examine variables

Source - https://ss64.com/nt/cmd.html

这篇关于使用Excel宏执行命令并关闭cmd窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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