Results 1 to 9 of 9
  1. #1
    New Lounger
    Join Date
    Jul 2005
    Location
    Canada
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    'Apply Template' advice requested (2003)

    Greetings all. I'm a long-time Outlook add-in developer just entering the Word (and later, Excel, etc) add-in world. My basic add-in development is going mostly fine, but of course I'm dealing with the "wouldn't it be cool if..." requests coming down the pipe. The current request is along the lines of "When creating a new document, pop up a dialog asking for a handful of fields, stick the responses into custom properties and also tack a bunch of boilerplate text at the top of the new document with these fields". Of course, what *they* want is specific to them, and doesn't make a hell of a lot of sense to a "general" product offering (which the add-in is supposed to be).

    I know what you're thinking: "that's what templates are for!". So the following paraphrases my conversations with them so far:

    Me: So make a custom template with an AutoNew macro that pops up your dialog and stuff the custom properties. The template will also include the boilerplate.
    Them: Yeah, but users need to do File|New *and* choose our template, and most just choose "Blank Document".
    Me: Okay, so put your customizations into Normal.Dot, and use Group Policy to push out your customized version, so all blank documents will have your stuff.
    Them: Yeah, but some users have personalized their own Normal.Dot and don't want to lose their own stuff.
    Me: Argh! (well, okay, I didn't *say* that, but I was thinking it)

    So, since they're getting the add-in installed anyway (it does other stuff), it's easy to also install some sort of template on each machine. What I'm not sure of is whether it's possible to force all new documents based on "Blank Document" to instead use my supplied template, *or* merge in a pre-existing boilerplate document and run a macro from an external document. I really don't want to put this customer-specific stuff into my actual add-in.

    Right now, I'm experimenting with having the add-in stick in a field like "{ INCLUDETEXT <my boilerplate doc> }" (where the path to this document would be loaded from the add-in's options settings). And it looks like I can use Application.Run to execute a macro in my supplied document to pop up the dialog and stuff the custom properties (though I haven't tried that yet).

    My question for y'all is: am I more or less on the right track here? Is there a better way to accomplish their goal that perhaps I'm not seeing?

    Thanks;
    Brad.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: 'Apply Template' advice requested (2003)

    Welcome to Woody's Lounge!

    Your add-in could include a custom toolbar with a button that creates a new document from your template. Easier for the user than selecting File | New... etc,
    Or you could create a macro named FileNewDefault, it will hijack the New button on the Standard toolbar and the Ctrl+N shortcut key.

  3. #3
    New Lounger
    Join Date
    Jul 2005
    Location
    Canada
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 'Apply Template' advice requested (2003)

    I suspect the argument against the toolbar button is that they'll expect the user to click *it* instead of the normal button. They don't seem to have a very high opinion of their users to remember stuff like that. :-)

    The FileNewDefault approach seems do-able, but how would one do that "remotely" (ie. programmatically from within an add-in or via Group Policy)? For our purposes we're going to assume that any solution that involves actually "touching" the end user's computer won't fly. Everything needs to be pushed out from the domain server (via Group Policy).

    I *believe* that if the user does File|New and selects a different template (perhaps one of their own creation), that's an acceptable limitation. Otherwise I'm stuck hacking stuff in via the add-in.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: 'Apply Template' advice requested (2003)

    If you put macros named FileNew and FileNewDefault in your add-in, they will automatically be used when the user presses Ctrl+N or the New button on the standard toolbar. If you also want to intercept the File | New..., From General Templates action, you'd have to create a FileNewDialog macro, but take care not to disable the selection of other templates than yours (unless that is what you want).
    Just installing your add-in is enough, you don't have to modify the users' Normal.dot or something like that.

  5. #5
    New Lounger
    Join Date
    Jul 2005
    Location
    Canada
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 'Apply Template' advice requested (2003)

    In my case we're talking about a COM Add-In written in C++, which complicates things somewhat. Although I can't see an obvious mechanism to embed a macro within a COM Add-In, I can trap various events like OnNewDocument. That part is easy. What I'm trying to stay away from is putting the dialog and body-tweaking stuff *in* my COM Add-In.

    But maybe the solution is a separate add-in that uses the macros you speak of. That can be customer-specific and separate from my main add-in (because, in reality, there's very little need to combine them). That said, can you point me towards any samples (VB, C++ or C# would do) showing me how to embed the macros you speak of? It's worth a try.

    Thanks for following up. I'm learning good stuff here. :-)

    Brad.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: 'Apply Template' advice requested (2003)

    I don't know anything about C++ or COM-add-ins. Hopefully someone else can help you further.

  7. #7
    New Lounger
    Join Date
    Jul 2005
    Location
    Canada
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 'Apply Template' advice requested (2003)

    Yeah, I should have specified COM Add-In at the beginning. But I think we can separate things out and look at making a non-COM Add-In with the macros you mention. Word refers to these using the .wll extension, and I assume they're written in VBA. This may be the breakthrough that I'm looking for, so now I'm going to see what I can find with respect to same add-ins with source code to play with.

    If this pans out, then what I'll be doing is telling the bosses to farm out *that* add-in creation to some consultant or something (or get the customer to do it themselves), and free me up to focus on my primary task of working on the COM Add-In (which does stuff almost *totally* unrelated to all we've spoken of here).

    Are you aware of any samples *with source* covering these (non-COM) add-ins and how to put the aforementioned macros into them? I'll read just about anything with the aim of coming up with some hacked-up proof-of-concept to show the bosses how "somebody" (read: not me) will accomplish the goal and then punt it. I *like* punting things. :->

    Brad.

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: 'Apply Template' advice requested (2003)

    A standard add-in for Word is a template (.dot) stored in the startup location for Word (in WinXP, the default is Cocuments and Settings<username>Application DataMicrosoftWordStartup, but the location can be set by the user or by a policy). Such add-ins are also called global templates.
    You create such a template within Word, and write macros in the Visual Basic Editor available in Word, using VBA. The code in an add-in is not essentially different from other Word VBA code.

  9. #9
    New Lounger
    Join Date
    Jul 2005
    Location
    Canada
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 'Apply Template' advice requested (2003)

    Excellent. I'm familiar with the concept of global templates (though I've never actually played with them before). I'll mess with that for a while. I was confused by Word's "Global Templates & Add-Ins" dialog providing both *.dot and *.wll extensions.

    I'm glad we had this chat. You may have saved me a heap of work. :-)

    Brad.

Posting Permissions

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