I need to write a macro in Excel VBA that completes the process running in windows tasks AFTER excel has been closed. I tried to do this on the event workbook_BeforeClose
Private Sub Workbook_BeforeClose(CANCEL As Boolean) Run "MacroCloseProcess" End Sub
Here where MacroCloseProcess is defined as
Private Sub MacroCloseProcess() Dim oWMT As Object, oProcess As Object Set oWMT = GetObject("winmgmts://") For Each oProcess In oWMT.InstancesOf("Win32_Process") If (oProcess.name) = pWcfHostApp Then If oProcess.Terminate() = 0 Then Exit Sub End If Next End Sub
This works, BUT, if there are changes made to the book, excel gives the user the option "Do you want to save the changes made to" Sheet1.xlsx "? Save, not save, cancel
If the user clicks on cancel, Excel does not exit (according to the design), but oh, the process is completed because it was in the "BeforeClose" event. How can I write this code so that it gets after closing Excel?
source share