raghuram.star
Board Regular
- Joined
- Sep 5, 2012
- Messages
- 102
Hi
I have problem in running ".bat" files through VBA, but when I run ".bat" file it executing properly. but not through VBA. Below is the code I'm using
Another peace of code I used is
But none of them are working... I have used this code a long back, but not sure what I'm missing....
Is there a way to run a .bat file directly, without opening two CMD windows? or a way to close the first CMD window (which is been opened through VBA), after running the .bat file (second CMD window is closed using Exit Command with in .bat file)
Thank you
I have problem in running ".bat" files through VBA, but when I run ".bat" file it executing properly. but not through VBA. Below is the code I'm using
Code:
Sub RunBatFile() Dim txtFpath, FilePath As String
txtFpath = wksCmdJen.Range("C12").Value ' given path is C:\Elements
FilePath = txtFpath & "\FetchElements.bat"
ChDrive "C"
RSP = Shell(Environ$("COMSPEC"), vbNormalFocus)
Application.Wait Now + TimeValue("00:00:01")
SendKeys "CD " & txtFpath & "{ENTER}", True
Application.Wait Now + TimeValue("00:00:01")
SendKeys "start " & FilePath & "{ENTER}", True
Application.Wait Now + TimeValue("00:00:01")
End Sub
Another peace of code I used is
Code:
Call Shell("cmd " & FilePath, vbNormalFocus)
But none of them are working... I have used this code a long back, but not sure what I'm missing....
Is there a way to run a .bat file directly, without opening two CMD windows? or a way to close the first CMD window (which is been opened through VBA), after running the .bat file (second CMD window is closed using Exit Command with in .bat file)
Thank you
Last edited: