Korean_Of_the_Mountain
Korean_Of_the_Mountain

Reputation: 1577

Execute command with Excel macro and close cmd window

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.

Upvotes: 5

Views: 20310

Answers (2)

Vityata
Vityata

Reputation: 43585

/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

Upvotes: 2

nani gadde
nani gadde

Reputation: 58

Here is code for it

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

I replaced /k with /c and now it closes the window.

Upvotes: 3

Related Questions