Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@danwagnerco
Last active September 20, 2015 02:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danwagnerco/dfb6e9051412a04f7266 to your computer and use it in GitHub Desktop.
Save danwagnerco/dfb6e9051412a04f7266 to your computer and use it in GitHub Desktop.
This script runs a batch file from VBA using the WshShell object
Option Explicit
Public Sub RunBatchFile()
Dim strCommand As String
Dim lngErrorCode As Long
Dim wsh As WshShell
Set wsh = New WshShell
'Run the batch file using the WshShell object
strCommand = Chr(34) & _
"C:\wshshell-fun\Create New 2015 Project Folder.bat" & _
Chr(34)
lngErrorCode = wsh.Run(strCommand, _
WindowStyle:=0, _
WaitOnReturn:=True)
If lngErrorCode <> 0 Then
MsgBox "Uh oh! Something went wrong with the batch file!"
Exit Sub
End If
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment