Skip to content

Instantly share code, notes, and snippets.

@addohm
Last active November 30, 2018 04:17
Show Gist options
  • Save addohm/a7544538d1c98e7db304423568cafeda to your computer and use it in GitHub Desktop.
Save addohm/a7544538d1c98e7db304423568cafeda to your computer and use it in GitHub Desktop.
VBA Example of Shell Execute that waits for completion and returns exit code
Private actLocation As Integer
Private actPrinterType As Integer
Private actSerialNumber As String
Private actPath As String
Private actStatusCheck
Private actVersion As Integer
Private actBoxID As Integer
Option Explicit
Public Property Let Path(ByVal NewValue As String)
actPath = Chr(34) & NewValue & Chr(34)
End Property
Public Property Get Path() As String
Path = actPath
End Property
Public Property Let PrinterType(ByVal NewValue As Integer)
actPrinterType = NewValue
End Property
Public Property Get PrinterType() As Integer
PrinterType = actPrinterType
End Property
Public Property Let Location(ByVal NewValue As Integer)
actLocation = NewValue
End Property
Public Property Get Location() As Integer
Location = actLocation
End Property
Public Property Let SerialNumber(ByVal NewValue As String)
actSerialNumber = NewValue
End Property
Public Property Get SerialNumber() As String
SerialNumber = actSerialNumber
End Property
Public Property Let StatusCheck(ByVal NewValue As Boolean)
actStatusCheck = NewValue
End Property
Public Property Get StatusCheck() As Boolean
StatusCheck = actStatusCheck
End Property
Public Property Let Version(ByVal NewValue As Integer)
actVersion = NewValue
End Property
Public Property Get Version() As Integer
Version = actVersion
End Property
Public Property Let boxID(ByVal NewValue As Integer)
actBoxID = NewValue
End Property
Public Property Get boxID() As Integer
boxID = actBoxID
End Property
Public Function Execute() As Integer
Dim wsh As Object
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
Dim exitCode As Integer: exitCode = 1
Dim fullExecutionString As String: fullExecutionString = ""
Set wsh = VBA.CreateObject("WScript.Shell")
'Run program with arguments and wait for the program to finish
If Me.PrinterType = 1 Then exitCode = wsh.Run(Me.Path & " /serial=" & Me.SerialNumber & " /position=" & Me.Location & " /print", windowStyle, waitOnReturn)
If Me.PrinterType = 2 Then exitCode = wsh.Run(Me.Path & " /boxid=" & Me.Location & " /version=" & Me.Version & " /print", windowStyle, waitOnReturn)
Execute = exitCode
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment