• autoNew vs document_new (Word 2000)

    Author
    Topic
    #367744

    Hi folks
    Can someone pleas explain the distinction between the AutoNew procedure and new_document events.
    Typically I might call AutoNew from a module which displays a form.

    I figured that
    sub document_new
    frmFormName.show
    end sub

    may do something similar but it doesnt ..

    Cheers & thanks
    Geof

    Viewing 2 reply threads
    Author
    Replies
    • #574416

      Autonew is a macro that runs every time a new document is created. You name it AutoNew and you don’t even need to call it in another macro. New Document event you need to call. You cannot have a macro named New Document and have it automatically run when a new document is created.
      At least, that’s my spin on it.
      Hope that helps.

    • #574485

      You might want to look at Running a macro automatically when a document is created, opened or closed.

      A procedure named AutoNew or named Document_New (but not new_document) will run whenever a new document is created based on the template containing the procedure. Document_New may also be triggered even if placed in a global template.

      • #574573

        Charles,

        That’s a good link as Dave Rado’s article covers the pertinent information. One thing to clarify though, Document_New will not run from a global template, unless you are creating a new document based on that global template (which one wouldn’t want to do).

        The topic can be confusing because there are actually three possible New document event procedures: Document_New (which gets placed in the ThisDocument module of a template that you base documents on); AutoNew (which typically would get placed in Normal.dot though as Dave points out, that can be a bad idea); and the application-level Document_New event.

        Distilling all of these choices down, the best bet for most situations is to use the Document_New event procedure in an attached template. One advantage of using this, not mentioned in Dave’s article, is that Document_New, being by default a Private Sub, will not appear in the user’s available list of macros, while AutoNew will.

        Gary

        • #574579

          You can set the Document_New to run from a global by putting it in a class module.

          • #574582

            Are you talking about the application-level “Application_DocumentNew” event procedure (which goes into a class module) or are you talking about putting “Document_New” in a class module? – if the latter, I’m unfamiliar with doing that – what are the uses for that?

            Gary

    • #574594

      Thanks to Rebecca, Charles & Gary
      The topic just gets better & better. I haven’t used ‘this document” much in the past to store procedures.
      Maybe I will in the future and store document_new() procedures there instead of using the AutoNew()

      If I understand what I am reading …

      private sub document_new()
      frmFormName.show
      End sub

      stored in “This document” of a template will do the same thing as “AutoNew()” stored in a module and will not show in the users list of macros.

      Have I bee n missing anything by not using ‘this document”

      Cheers & thanks

      Every day is a school day.
      Geof

    Viewing 2 reply threads
    Reply To: autoNew vs document_new (Word 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: