Reputation: 23
I'm hoping there's a simple solution here, but not being a coder I have no idea what the solution should be.
In MS Word I have a VBA userform that can either be submitted, skipped or discarded. The present issue is with the "Discard" button. Its purpose is to exit the form completely using 'ThisDocument.Close' so that nothing is erroneously submitted for review; however, when the user clicks this button to abandon the userform it seems to hide all other Word documents that may be open as well. Word disappears from the Taskbar. The documents do not close, and I know this because when I open Word afresh they are still open under the ribbon in View > Switch Windows.
The following is my code:
Private Sub CancelBtn_Click()
Dim SureCancel As Integer
SureCancel = MsgBox("Are you sure you want to abandon this sheet? _
Changes will not be saved!", vbYesNo)
If SureCancel = vbYes Then
ThisDocument.Close wdDoNotSaveChanges
End If
End Sub
I have also tried to use Application.Visible = True
after the End If
to no avail.
Any help / ideas greatly appreciated.
Upvotes: 0
Views: 101
Reputation: 23
I've made a couple of minor additions to my code and it now does exactly what I want to.
Private Sub CancelBtn_Click()
Dim SureCancel As Integer
SureCancel = MsgBox("Are you sure you want to abandon this sheet? _
Changes will not be saved!", vbYesNo)
If SureCancel = vbYes Then
If Documents.Count > 1 Then
Application.Visible = True
End If
ThisDocument.Close wdDoNotSaveChanges
End If
End Sub
The If Documents.Count > 1
clause checks whether anything else is open in Word and only if that is true does the Application then appear again, otherwise it quits.
Upvotes: 1