Write a Macro in VBA - excel AFTER the user has closed the Excel

前端 未结 3 1883
闹比i
闹比i 2021-02-10 02:20

I need to write a macro in Excel VBA, that terminates a process running in windows tasks AFTER the excel has been closed down. I tried it doing this on event workbook_BeforeClos

3条回答
  •  不思量自难忘°
    2021-02-10 02:44

    Some of the other ideas are ok and I agree with saving first, but you should ask for their permission beforehand. This also allows the user to save first as it checks first if it's saved.

    You should invoke the user to save the workbook before you terminate. E.g.

    Private Sub Workbook_BeforeClose(CANCEL As Boolean)
    
    If Not Me.Saved Then 
        Msg = "Do you want to save the changes you made to " 
        Msg = Msg & Me.Name & "?" 
        Ans = MsgBox(Msg, vbQuestion + vbYesNoCancel) 
        Select Case Ans
            Case vbYes 
                Me.Save 
            Case vbNo 
                Me.Saved = True 
            Case vbCancel 
                Cancel = True 
                Exit Sub 
        End Select
    End If
    
    Run "MacroCloseProcess"
    
    End sub
    

提交回复
热议问题