Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Apr 2002
    Location
    Texas, USA
    Posts
    208
    Thanks
    0
    Thanked 1 Time in 1 Post

    How to use Add-in in Word (2000/2002)

    I am an Excel user and am familiar with the object hierarchy of Excel and what events fire at what times. I am now looking at trying to create within the Word environment the same functionality that an Excel Add-in does within Excel. Now this may not be the best route for what I am trying to accomplish so any suggestions as to alternatives are welcome.
    I have started experimenting with the Word document events and I am unable to get any of the events to trigger. I have placed a stop command in both Document_Open and Document_Close and nothing happens.
    My end goal is to have code that allows me to control the processing of a doc file after it has been opened. The file uses Mail Merge to pull data via a hdr file.
    Can anyone either provide some direction/insight regarding Word/Document events and the best way to create Excel AddIn like functionality within Word? I looked at Words Add-Ins screen and played with it some but what puzzles me is that when a DOT file is loaded as an Add-In you are unable to view it's objects within Project Explorer in the VB IDE.

    Thanks
    Ed

  2. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to use Add-in in Word (2000/2002)

    Hi Ed:
    I'm not a VBA expert, but I can tell you that,in Word, you can only view an add-in template's objects if you open the template, whether or not it's loaded. The only exception is normal.dot.
    Cheers,

  3. #3
    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: How to use Add-in in Word (2000/2002)

    Are you putting the procedures in the ThisDocument class module in your template? That usually is the easiest way, but I would expect it to work only for documents based on (attached to) that template (File>New.../Tools>Templates and Add-ins...>Attached template). I'm not sure the ThisDocument module, or more specifically, document level events, have any meaning in a global template. (Probably because I've never used it in that context.)

    Word also supports AutoOpen, AutoNew and AutoClose to run code when those "events" occur. These are the legacy of very early versions of Word for Windows, and sometimes are easier to use than the newer event model.

    In the MSDN documentation at Microsoft.com, you might find other information about which of Word's events fire when.

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: How to use Add-in in Word (2000/2002)

    Ed,

    It sounds very likely that you should be able to do what you need, using document events in Word.
    Just adding on to Jefferson's comments, you basically have two ways to respond to a document open event in Word:

    1) base your documents on a specific template (an "attached template" rather than an add-in template). In the ThisDocument module of the attached template, you can have Document_New and Document_Open procedures which will run when you create a new document based on this template or open an existing one.

    2) create a Word global add-in template and place it in the Word Startup directory so that it loads automatically whenever you launch Word. In this global template, set up an application-level event handler that will respond to application document_new and document_open events.

    The first option is much easier to implement so is usually the best way to go.
    The second option would be used if you need to have code that runs when any document opens (not just documents based on a specific template).

    Gary

Posting Permissions

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