Hi All,
Im using VBA to launch a separate windows program based on the values of a couple of cells.
The program is for some label printing software that calls up a label template based on the user scanning a QR code that populates the cell values that pick the correct label from a folder full of templates in explorer.
Everything works OK, but I have to be able to close the old label template before I scan the new code and open the new label to avoid the wrong label bring printed.
Currently I'm using a "terminate app" code which I run before using a Shex.Open (tgtfile) command to re-launch the labelling software. This closes down the whole labelling application for the Shex.Open command to then open it again.
The problem is its pretty slow, as the whole application effectively restarts every time.
I was wondering if anyone knew a way that I could just close the active label but leave the labelling software itself open, to speed up the loading times.
Appreicate any help.
Thanks
Sub TerminateApp()
'---------------------------------------------------------------------------------------
' Terminates the exe process specified.
' Uses WMI (Windows Management Instrumentation) to query all running processes
' then terminates ALL instances of the exe process held in the variable strTerminateThis.
'---------------------------------------------------------------------------------------
Dim strTerminateThis As String
'The variable to hold the process to terminate
Dim objWMIcimv2 As Object, objProcess As Object, objList As Object
Dim intError As Integer
'Process to terminate – you could specify and .exe program name here
strTerminateThis = "NiceLabelDesigner.exe"
'Connect to CIMV2 Namespace and then find the .exe process
Set objWMIcimv2 = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set objList = objWMIcimv2.ExecQuery("select * from win32_process where name='" & strTerminateThis & "'")
For Each objProcess In objList
intError = objProcess.Terminate 'Terminates a process and all of its threads.
'Return value is 0 for success. Any other number is an error.
If intError <> 0 Then Exit For
Next
'ALL instances of exe (strTerminateThis) have been terminated
Set objWMIcimv2 = Nothing
Set objList = Nothing
Set objProcess = Nothing
End Sub
Im using VBA to launch a separate windows program based on the values of a couple of cells.
The program is for some label printing software that calls up a label template based on the user scanning a QR code that populates the cell values that pick the correct label from a folder full of templates in explorer.
Everything works OK, but I have to be able to close the old label template before I scan the new code and open the new label to avoid the wrong label bring printed.
Currently I'm using a "terminate app" code which I run before using a Shex.Open (tgtfile) command to re-launch the labelling software. This closes down the whole labelling application for the Shex.Open command to then open it again.
The problem is its pretty slow, as the whole application effectively restarts every time.
I was wondering if anyone knew a way that I could just close the active label but leave the labelling software itself open, to speed up the loading times.
Appreicate any help.
Thanks
Sub TerminateApp()
'---------------------------------------------------------------------------------------
' Terminates the exe process specified.
' Uses WMI (Windows Management Instrumentation) to query all running processes
' then terminates ALL instances of the exe process held in the variable strTerminateThis.
'---------------------------------------------------------------------------------------
Dim strTerminateThis As String
'The variable to hold the process to terminate
Dim objWMIcimv2 As Object, objProcess As Object, objList As Object
Dim intError As Integer
'Process to terminate – you could specify and .exe program name here
strTerminateThis = "NiceLabelDesigner.exe"
'Connect to CIMV2 Namespace and then find the .exe process
Set objWMIcimv2 = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set objList = objWMIcimv2.ExecQuery("select * from win32_process where name='" & strTerminateThis & "'")
For Each objProcess In objList
intError = objProcess.Terminate 'Terminates a process and all of its threads.
'Return value is 0 for success. Any other number is an error.
If intError <> 0 Then Exit For
Next
'ALL instances of exe (strTerminateThis) have been terminated
Set objWMIcimv2 = Nothing
Set objList = Nothing
Set objProcess = Nothing
End Sub