Cancel = True
08.10.2018 10:57:54
Markus
ich habe eine kleine Prozedur geschrieben, die mir das Schließen des Dokuments bei bestimmten Zuständen verbieten soll.
Die Prozedur "Field_Check" steht in Module 1. Aufgerufen wird sie sowohl über das Sheet1 mit _
Hilfe eines Worksheet_Change als auch über ThisWorkbook mittels Workbook_BeforeClose.
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("C2:E5")) Is Nothing Then Exit Sub
Call Module1.Field_Check
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call Module1.Field_Check
End Sub
Die eigentliche Prozedur in Module 1 sieht dann wie folgt aus:
Public Sub Field_Check()
Dim intCol As Integer
Dim intRow As Integer
Dim i As Integer
For intRow = 3 To 5
i = 1
For intCol = 3 To 5
If Cells(intRow, intCol) > Cells(intRow, intCol - i).Value Then
Cells(intRow, intCol).Select
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
If Cells(7, intCol).Value = "" Then
Cells(7, intCol).Select
Cancel = True
MsgBox "Comment required in" & ActiveCell.Address, vbExclamation
End If
End If
If Cells(intRow, intCol)
Leider funktioniert das Cancel = True nicht und ich kann das Dokument schließen, obwohl die Kommentarzellen C7:E7 leer sind.
Steht "Cancel = True" an der falschen Stelle?
Vielen Dank vorab
Markus