I have an Excel sheet with multiple data columns. The data of the first column is filled by users, scanning a NFC tag, the content (MemberId) is copied to the active cell using an external commeercial tool that reads the data from an NFC reader (ACR122u-A9) and puts it in the active cell. However, when data in the other columns is entered (by desk employee, adding data related to an already scanned NFC code), I want to block the NFC input temporary, to prevent that scanned data appears in the other columns.
I implemented this using Excel’s ProcessSelectionChange event: when in first column, start the external application using the Exec_TaskStartByName routine (see below) and when switching to a different column, kill it using routine Exec_TaskKillByName.
I noticed that the external program starts the JAVA framework (TaskManagement view), so kill the application in fact means kill the Java.exe process.
As such, above works, but re-starting the application each time takes too much time, resulting in a “dead-time” (tool not ready yet). Instead of killing/restarting the application each time, I am wondering if a started process can be suspended (temp stop execution) and resumed when back in the first column. Suspend/Resume is expected to take less time then kill/start.
- If not, are there faster ways to start an external program other than I do (see code below)?
I noted that if I do not execute the ChDir first in the Exec_TaskStartByName routine, the application is not started.
Function Exec_TaskStartByName( _
ByVal argFilePath As String, _
ByVal argFileName As String, _
ByRef argTaskId As Long)
'First switch to the appropriate directory before starting the command
ChDir (argFilePath)
argTaskId = Shell(argFilePath & argFileName, vbMinimizedFocus)
Exec_TaskStartByName = (argTaskId > 0)
End Function
Function Exec_TaskKillByName( _
ByVal argFileName as string)
Dim oServ As Object
Dim cProc As Variant
Dim oProc As Object
Set oServ = GetObject("winmgmts:")
Set cProc = oServ.ExecQuery("Select * from Win32_Process")
For Each oProc In cProc
If (oProc.Name = argFileName) Then
Exec_TaskKillByName = oProc.Terminate
Exit For
End If
Next
End Function
See description, starting/killing the application with the provided code works, but starting takes to much time
8