Create a macro to exit Word without saving document

hankbum
hankbum used Ask the Experts™
on
How to create a macro to exit Word without saving the document ... or possibly retrieve one from a macro source.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2006
Commented:
you can put this in the thisdocument object of the vb editor

Option Explicit

Private Sub Document_Close()
  ThisDocument.Saved = True
End Sub

Author

Commented:
Sorry:  

I'm somewhat new to Word and VBA in general although I do have much experience in general.  Programming is just my weak point and I'm afraid Word is very non-intuitive and frustrating for me.  I have made forms in PageMaker, Excel, WordPerfect, Omniform.  There is a reason I must make this one in Word and I am determined to finish it.

For whatever reason I am not getting your solution to work.  I cut and pasted a sample macro below with no commands.  I can go back into visual basic and place whatever you tell me (exactly) and wherever to put it (exactly).

Hope I'm not a pain :(

Sub Macro3()
'
' Macro3 Macro
' Macro recorded August 28, 2003 by H L BUMGARDNER
'
End Sub
Top Expert 2006

Commented:
easier talking when you see something

http://www.bredlum.com/ee_temp/20722986.doc

-goto the vb editor with alt+f11
-then have a look at the thisdocument object by doubleclicking on it
-there will be the sub above

it will tell word that it is saved when you close it down so be sure to always explicitly save when you want to save something in this document else it will not ask you for saving on close

what are you trying to do here?
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Author

Commented:
I wasn't able to open your document at the link you gave.  How about emailing it to me at   hankbum@earthlink.net  

It's a fast connection.

What I'm doing exactly is making a program for prescribing drugs for patients.  My first page has hyperlinks to individual pages throughout the document, each page has a different drug.  I have a fill-in box pop up when the program opens and I simply fill in the Patient_Name, Address, Refill_Information, etc.  The information flows into the same fields on every page.  I then click on the drug I want and am taken to that page.  I run a macro to print that page plus a copy with a watermark "copy" for our files.  I would then like to exit the program without saving the information so that the fields will be empty for the next patient.  As an alternative, if I could automatically save a copy each time in a particular directory as Document_001, Document_002, etc., it would be OK, except that because this file is about 50 pages long (and likely to grow longer), the directory size would grow big fairly quickly.  If I could save just the individual page I printed perhaps as Smith_[Current_Date] or something like that it would fine.  
Top Expert 2006

Commented:
works for me will mail anyway

but never post your mail addy here or only in a format like hankbum at earthlink dot net

you can ask a 0 point question in community support
http://www.experts-exchange.com/Community_Support/

to edit the post
http://www.experts-exchange.com/Q_20722986.html#9243231

Author

Commented:
I discovered I am now able to open your document from the link you gave me.  The servers must have been busy earlier.  I was unable to see any text in your document.  What am I supposed to do exactly.  I looked at the text in the macros and I noticed the reference to your document but no macros in the ThisDocument subdirectory.

I don't think I'm paying you enough for this.

Thanks for the advice RE: email addy's

If it would help for me to send a small sample of my form I can do that easily.
Top Expert 2006

Commented:
that's ok send it you got my addy :)

left the document empty to demonstrate only the code

you can type any text in it and close the document it will not ask for saving i thought that was the question
Top Expert 2006

Commented:
my fault tried it with

Option Explicit

Public Sub AutoClose()
 ThisDocument.Saved = True
End Sub

Public Sub AutoExit()
 ThisDocument.Saved = True
End Sub

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial