postelrich
New Member
- Joined
- Feb 24, 2011
- Messages
- 31
I have made a userform that popsup when someone saves the file that asks them to put in some comments and copies that to a changelog in the workbook. Everything works fine except for the cancel button which will still save if chosen. I have tried searching and a bunch of methods. Here is what I have so far.
Code for the event:
Code for the Userform:
Code for the event:
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
UserForm1.Show
If CancelIt = True Then
Cancel = True
End If
Unload UserForm1
End Sub
Code for the Userform:
Code:
Public CancelIt As Boolean
Private Sub CommandButton1_Click()
Dim comments As String
Dim LastRow
comments = TextBox1.Value
With Sheets("Changelog & Reference")
LastRow = .UsedRange.Rows.Count + 1
.Range("A" & LastRow).Value = Now
.Range("B" & LastRow).Value = Environ("USERNAME")
.Range("C" & LastRow).Value = comments
End With
Unload UserForm1
End Sub
Private Sub CommandButton2_Click()
CancelIt = True
UserForm1.Hide
End Sub
Last edited: