Hi Poss:
OK, let me give you some ideas. The trick is to make your code go find the
template. VBA/AppleScript contain a set of properties you can retrieve that
lets you know where things like the active document, the attached template,
the template folder and the startup path are. Here's some code that goes
and finds the template it wants:
Sub UpdateStyles()
Const Message As String = "Do you want to update all document styles?"
Dim WkrsCompTemplate As String
Dim doIt As Long
WkrsCompTemplate = Options.DefaultFilePath(wdStartupPath) & "\" &
TemplateName
' Updates styles
Application.OrganizerCopy _
Source:=WkrsCompTemplate, _
Destination:=ActiveDocument.FullName, _
Name:="Question", _
Object:=wdOrganizerObjectStyles
If ActiveDocument.Name <> TemplateName Then
doIt = MsgBox(Message, vbOKCancel, "Attach Template Macro")
If doIt = 1 Then
With ActiveDocument
.AttachedTemplate = WkrsCompTemplate
.UpdateStyles
.AttachedTemplate = Application.NormalTemplate
End With
End If
End If
End Sub
This macro updates a documents styles then attaches Normal template (to
prevent any further updates).
The active ingredient is Options.DefaultFilePath(wdStartupPath) which
returns the path to the user¹s Word:Startup folder as a string. There are
various options: WdDefaultFilePath can be one of these WdDefaultFilePath
constants.
wdAutoRecoverPath
wdCurrentFolderPath
wdGraphicsFiltersPath
wdProgramPath
wdStartupPath
wdTempFilePath
wdToolsPath
wdUserOptionsPath
wdWorkgroupTemplatesPath
wdBorderArtPath
wdDocumentsPath
wdPicturesPath
wdProofingToolsPath
wdStyleGalleryPath
wdTextConvertersPath
wdTutorialPath
wdUserTemplatesPath
This means all you have to do is tell the user to put your template in their
³User Templates Folder². You can even make a macro to do it for them, with
a button that says ³Click here to install²
The variable TemplateName has been pre-loaded with the name of the template
we want (just the name, without the path) as a string. I normally have a
separate module that contains nothing but constants, to enable me to quickly
re-purpose macros for different customers. That one is defined as:
Public Const TemplateName As String = "Tender Work in Progress v5.dot"
The keyword ³Public² makes it persistent and available to any macro anywhere
in the same template.
Sorry, I can¹t do this stuff in AppleScript. But Paul can, and will be very
helpful if you ask nicely
Note that the last time Paul and I tried to get this stuff working in
AppleScript, we discovered some of it doesn¹t work right in AppleScript.
And some of those constants I gave you in the list above will not be
available on the Mac, or will not work properly, because I pinched the list
from Word 2003 Help.
Hope this helps
Thank you for your helpful response.
Your concerns about users placing the templates in the right place are
well-founded. I'm attempting to get around this by furnishing not only
an updated template, but a script bundle that includes the new template
as one of its components. The Applescript I'm using is for this part
is:
set myPath to path to me as string
set newTemplate to (myPath &
"Contents:Resources:templateName_rev3.dot")
open newTemplate
Now that the proper template is open, I have to script a way to save it
to the right directory and we'll be set.
--
Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.
John McGhie <
[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 4 1209 1410