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 tool that reads the data from an NFC reader (ACR122u-A9) and puts it in the active cell. However, when data in the other cells is entered (by desk employee), I want to block the NFC input temporary.
When starting the external application, I notice that it starts JAVA.
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 (in fact kill the Java.exe).
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 starting/killing the application each time, I am wondering if a started process can be put “OnHold” (temp stop execution), so it does not need to re-started each time. Disable/Enable is expected to take less time then kill/start.
- If not, are there faster ways to start an external program than I use (see code below)?
I noted that if I do not execute the ChDir first in the Exec_TaskStartByName routine, the application is not started.
Any suggestions are welcome
*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)
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
user26618353 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.