Ok i ran into a problem with my userform.
When the form is canceled I want to to not save the document. Even if the document is being closed and the Save Changes? option runs, this macro runs.
My problem was that the document was saving regardless after the Userform Cancel button was used. So I added Cancel = True to my workbook code.
Original Code:
New Code:
Userform Code:
Now my problem is the document does not save even when a comment is added and OK is clicked. It also wont Save As or Save on Close now either with this version of the macro. Any suggestions on what to add to my OkButton_Click to get it to save properly?
When the form is canceled I want to to not save the document. Even if the document is being closed and the Save Changes? option runs, this macro runs.
My problem was that the document was saving regardless after the Userform Cancel button was used. So I added Cancel = True to my workbook code.
Original Code:
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
frmCommentForm.Show
End Sub
New Code:
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
frmCommentForm.Show
Cancel = True
End Sub
Userform Code:
Code:
Private Sub CancelButton_Click()
MsgBox "If Comment History is not added, no changes will be saved.", vbCritical + vbOKOnly, "Cancel Comment"
Unload Me
End Sub
Private Sub OkButton_Click()
Set MySheet = Sheets("Update History")
NextCell = Sheets("Update History").Range("a65536").End(xlUp).Row + 1
MySheet.Unprotect "dstengineering"
MySheet.Cells(NextCell, 1) = Environ("username")
MySheet.Cells(NextCell, 2).Value = Now
MySheet.Cells(NextCell, 3) = txtComments.Value
MySheet.Protect "dstengineering"
Unload Me
End Sub
Now my problem is the document does not save even when a comment is added and OK is clicked. It also wont Save As or Save on Close now either with this version of the macro. Any suggestions on what to add to my OkButton_Click to get it to save properly?