Hello Dear programmers! Please help me solve the following problem with the vba code: the button in the excel 2003 book copies the application file "form_v1.exe" (this is a window with fields and the Close button) to the temporary folder from which this file is started immediately after copying. The user working with the book can complete the process "form_v1.exe" (close the window) or not. Question: As when closing this book: 1) complete the running process "form_v1.exe" if it is still running, i.e. interrupt it if necessary by force, 2) delete the process file "form_v1.exe" from the temporary folder. Note: The process file "form_v1.exe" may be with a different name, but the name always starts with "form *". The code below works correctly only if the user has completed the process before closing the book. Thanks for any of your tips.
Private Sub Workbook_BeforeClose(Cancel As Boolean) Dim Process As Object For Each Process In GetObject("winmgmts:").ExecQuery("Select * from Win32_Process") If Process.Caption Like "form*" Then Process.Terminate End If Next Kill Environ("temp") & "\" & "form*" End Sub