Results 1 to 2 of 2
  1. #1
    2 Star Lounger
    Join Date
    Sep 2006
    Posts
    166
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exit word (Word 2000)

    How can i write a macro on a word document, having the command to close the document with a cick ?

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Exit word (Word 2000)

    <P ID="edit" class=small>(Edited by jscher2000 on 18-Sep-06 12:14. )</P>The VBA macro code required to close the currently active document is simple:

    <code>ActiveDocument.Close</code>

    There are options for what to do about unsaved changes. You can read up on these in the VBA help file. As you may know, the simplest way to access VBA help is to create a new macro:
    1. <LI>In your Word document, press Alt+F8 to open the Macros dialog
      <LI>Type a name, such as <code>TestMacro</code>, to create it in a particular template or document, use the drop down control, then click Create
      <LI>Type or paste the code of interest between Sub TestMacro and End Sub
      <LI>Select an object, method, or property in the code and press F1
    But how to add this macro into your document?
    <UL><LI>The old way was a "macrobutton" field. This requires a double-click, and is tricky to use in a protected document (e.g., if your document is a protected form).
    <LI>A newer way is a control from the controls toolbox. I actually haven't used these, so I'm not sure how easy they are to connect to a macro. Probably not too bad.
    <LI>A third possibility is a document-specific toolbar, set to float around somewhere noticeable. I often do this for in-house solutions.[/list]Does that help?

    Added: I just noticed the name of this thread is Exit Word. To close Word in VBA, you can try Application.Quit, but I'm not sure it actually works from inside Word. (Some testing will be required.)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •