Returning the path to a misplaced Word Template's location

J

John Morley

The big issue is users installing templates we distribute into the wrong
templates folder on their Macintosh (if there are multiple template folders
containing a Normal template).

The solution I want to develop is a macro, built into a Word file that I can
email; then, the user just clicks the button to run the macro that finds
where the templates are now and moves them to where they should be
(Options.DefaultFilePath(wdUserTemplatesPath)).

My question is, from within Word on a Macintosh, how do I get VBA to return
the path to a Word template if I know only the file name of that Word
template?

This is a problem only on Macintosh, as the Windows installer is able to
query the registry and determine where Microsoft Word is looking for its
templates. On the Mac side, we are using the StuffIt Installer Maker and
understand that it is not possible for it to obtain the path to the Templates
folder being used by Word.

Instead, it looks for the first Microsoft Word Template file named Normal it
can find and then installs the templates there. This works fine unless the
hard drive contains multiple Normal templates (and the wrong one is found
first) or Word is configured to look elsewhere for templates to use.

Any help would be very appreciated.
 
J

John McGhie

Hi John:

In VBA or AppleScript, the line:

application.normaltemplate.path

will return the location where the Normal Template currently in use now is.

The line:

Options.DefaultFilePath(wdUserTemplatesPath)

Will tell you where the template is supposed to be.

If you want to search the user's drive for the file, you will need to use
AppleScript to do that. Word VBA does not have a file search function on
the Mac.

Hope this helps

The big issue is users installing templates we distribute into the wrong
templates folder on their Macintosh (if there are multiple template folders
containing a Normal template).

The solution I want to develop is a macro, built into a Word file that I can
email; then, the user just clicks the button to run the macro that finds
where the templates are now and moves them to where they should be
(Options.DefaultFilePath(wdUserTemplatesPath)).

My question is, from within Word on a Macintosh, how do I get VBA to return
the path to a Word template if I know only the file name of that Word
template?

This is a problem only on Macintosh, as the Windows installer is able to
query the registry and determine where Microsoft Word is looking for its
templates. On the Mac side, we are using the StuffIt Installer Maker and
understand that it is not possible for it to obtain the path to the Templates
folder being used by Word.

Instead, it looks for the first Microsoft Word Template file named Normal it
can find and then installs the templates there. This works fine unless the
hard drive contains multiple Normal templates (and the wrong one is found
first) or Word is configured to look elsewhere for templates to use.

Any help would be very appreciated.

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Consultant Technical Writer
Sydney, Australia +61 4 1209 1410
 
J

John Morley

Dear John,

Thanks for your prompt reply. It's at least gratifying that the reason I
couldn't find the "filnd file" code I was looking for was that it doesn't
exist, rather than my inability to use the Help function within VBA.

Can AppleScript be used from within a macro resident within a VBA macro?
 
P

Paul Berkowitz

In VBA or AppleScript, the line:

application.normaltemplate.path

will return the location where the Normal Template currently in use now is.

No dot language in AppleScript, however. In AppleScript the equivalent is:



path of normal template

(which actually gives you the path to the _container_ of the normal
template, namely the Microsoft User Data folder in ~/Documents, if you
haven't moved it from its default location and substituted an alias. You'll
get the actual location, wherever it is. If you're going to use it further
in AppleScript (e.g. as an 'alias' i.e. file) stick a ":" onto the end of
it. If you want the path to the actual Normal template itself stick
":Normal" onto the end of it.
The line:

Options.DefaultFilePath(wdUserTemplatesPath)

Will tell you where the template is supposed to be.

In AppleScript that's

get default file path file path type user templates path

which for some obscure reason gives (like the VBA) a path entirely in
lowercase. That makes it completely useless: OS X requires that the disk
name be case-sensitive-correct (there must be Unix stuff going on in the
background). It will fix the case for the remaining folders and file in the
path, but the disk name (the first component of the path) must be
case-correct.

So you'd better forget this function and stick to the real path, not the
default.
If you want to search the user's drive for the file, you will need to use
AppleScript to do that. Word VBA does not have a file search function on
the Mac.

Probably what you need here is

path to home folder as Unicode text -- or 'as string'

which will get you the correct case.

path to documents folder as Unicode text

gets you further. Substitute either one, into the default file path.
Probably the easiest is

tell application "Microsoft Word" to set lcTemplatesPath to get default
file path file path type user templates path
set homeFolder to path to home folder as Unicode text
set AppleScript's text item delimiters to {":"}
set diskName to text item 1 of homeFolder
set restOfTemplatesPath to text items 2 thru -1 of lcTemplatesPath as
Unicode text
set AppleScript's text item delimiters to {""}
set mixedTemplatesPath to diskName & ":" & restOfTemplatesPath & ":"

(If it doesn't really exist you can't make it an 'alias', though.)

Using 'MacScript' in VBA, as JE suggests, is easy enough for one-line
scripts, but more compliated for multiline scripts. You need to replace the
line ends by ' & vbCr & ' in VBA.

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
J

John Morley

Dear Paul,

Thanks so much for the help and for the code. Looks as if I'll be getting a
book on AppleScript to get up to speed on that. Thanks for the push in that
direction.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top