wer kann helfen?
Ich möchte eine Prozedur ausführen beim Schließen der Arbeitsmappe. Vor dem schließen Frage ich mit einer MsgBox ab, ob die Prozedur ausgefürt werden soll oder nicht.
(die Prozedur an sich dürfte für meine Begriffe egal sein, es geht lediglich darum vom Blatt Erfassung einen Bereich auf das Blatt Historie zu kopieren).
Leider hat die MsgBox keine Auswirkung, die Prozedur wird IMMER ausgefürt. Bei Abbruch durch die MsgBox will ich aus der Prozedur raus, deshalb End.
Was ist mein Fehler?
Der Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
MsgBox "Erfassung festschreiben?" & Chr(13) & "Die Erfassung wird geleert!", vbOKCancel
'xxxxxxxxxxxxxxxxxx das funktioniert noch nicht, der Code wird immer ausgeführt _
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
If vbOKCancel = vbOK Then
Application.ScreenUpdating = False
Sheets("Historie").Unprotect Password:="123"
Sheets("Erfassung").Select
Rows("4:9").Select
Selection.Copy
Sheets("Historie").Select
Range("A100000").End(xlUp).Offset(1, 0).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("A100000").End(xlUp).Offset(-1, 1).Select
ActiveCell.SpecialCells(xlCellTypeSameValidation).Select
With Selection.Validation
.Delete
.Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
:=xlBetween
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
Sheets("Historie").Protect Password:="123"
Sheets("Erfassung").Select
Sheets("Erfassung").Unprotect Password:="123"
Range("B4:AZ9").Select
Selection.ClearContents
Selection.ClearComments
Sheets("Erfassung").Protect Password:="123"
Application.ScreenUpdating = True
Else
End
End If
End Sub