• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 635
  • Last Modified:

Shell Window not Closing

Hi Experts,

I'm using "Shell" in VBA to merge multiple CSV Files together but the CMD window isn't closing.
it does the job though and my macro then continues to Import the Merged file.

Why?
And how would i make it close automatically?
Sub Test()
Dim comStr as String
comStr = "CMD /k Copy " & Chr(34) & strDir & "\*.csv" & Chr(34) & " " & Chr(34) & "C:\all.txt" & Chr(34)
Call Shell(comStr)
End Sub

Open in new window

0
bromy2004
Asked:
bromy2004
2 Solutions
 
zorvek (Kevin Jones)ConsultantCommented:
Change:

comStr = "CMD /k Copy " & Chr(34) & strDir & "\*.csv" & Chr(34) & " " & Chr(34) & "C:\all.txt" & Chr(34)

To:

comStr = "CMD /C Copy " & Chr(34) & strDir & "\*.csv" & Chr(34) & " " & Chr(34) & "C:\all.txt" & Chr(34)

Kevin
0
 
zivkoCommented:
Hello,

Zorvek response is right but I think a little explanation would have been welcome:

The two involved CMD.exe switches here are:

/C      Carries out the command specified by string and then terminates
/K      Carries out the command specified by string but remains

So using /K, it is the normal behavior of the prompt to remain open after the command as been carried out.

Hope this will clarify the point.
0
 
bromy2004Author Commented:
I've given Zivko the majority because he was clear with his explanation.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now