Greetings all,
Big fan of VBA Express
Intro: Gov't worker in water quality trying to create a semi-automated process for review requests using a Word form with data captured in Access (for my database) but distributed to Excel (for those who ack!Access). The form will be filled out by various districts personnel in the agency located throughout the state and sent back via email. I'm not a VBA expert or programmer by profession. Rank amateur, green-as-grass. The form has potential for elegance (TY VBA!), but in my hands, I will be delighted to get the thing into production.
I've been "borrowing" code from several sites including Greg Maxey's but there are a few problems I can't seen to comprehend the issue to find a solution. So here I am. I have several questions all related to this project, but will start with this one.
OP is Windows XP with MSOffice 2007. The Word document is a macro-enabled template. The template has several form controls. The last one is a text form field that when the user moves out of the form field a userform automatically pops up giving the user several choices:
Save
Send as attachment
Cancel(return back to form)
Close and do not save
It is the last choice I have been banging my head on for a while. What I want to do is: close the userform, close the active document without saving.
I've tested some code separately and can get the userform to close OR get the active document to close without saving but NOT within the same procedure. It hangs up. I get the general run-time error '4198' command failed. I did get another error message once indicating that the word document could not close because a dialog box was still open. Makes sense...
Here is the code:
[vba]
Private Sub cmdStop_Click()
If MsgBox(prompt:="Do you really want to close?", Buttons:=vbOKCancel) = vbOK Then
Unload frmSaveAndSend
Application.DisplayAlerts = False
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
End If
End Sub
[/vba]
When debugging it highlights ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
I also tried calling a procedure before closing the document with no issues.
Thanks to all for your patience (as I'm afraid this is only the beginning).
Regards!