How to find MS Word's default file location

S

Southern at Heart

I have a Word template to share with others. I repeatedly have to explain
how they need to put it in their template folder before using it. Is there a
simple way to create an .exe file that all it does check to see what the MS
Word uses as the tempate folder and copys my template into it?
thanks.
ck
 
J

Jay Freedman

Southern said:
I have a Word template to share with others. I repeatedly have to
explain how they need to put it in their template folder before using
it. Is there a simple way to create an .exe file that all it does
check to see what the MS Word uses as the tempate folder and copys my
template into it?
thanks.
ck

Easy? No, that would be far too simple for anything named Microsoft. ;-)

The first step is to look in the registry at the key
HKEY_CLASSES_ROOT\Word.Document.8\shell\Open\command
The value of the (Default) item contains the path to the copy of WinWord.exe
that opens a document when you launch it from Windows Explorer. That path
contains the version number of that copy of Word; for example,
"C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE"
tells you that version 11 (that is, Word 2003) is the target.

The next step is to look in the registry at the key
HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Common\General
or the equivalent for whatever version of Office is being targeted. If the
key contains an item named UserTemplates, then the user has customized the
location of the User Templates folder to be different from the installation
default, and the value of the item is the folder where you should install
your template.

If there is no UserTemplates item in the key, then Word is using the
installation default. Unfortunately, that varies by Office version and
Windows version. For recent versions of Word on 32-bit Windows XP, it will
be
C:\Documents and Settings\<user name>\Application Data\Microsoft\Templates
It will be slightly different for 64-bit Windows and for Vista. If you can
expand environment strings in your program, it may be easier to look for
%appdata%\Microsoft\Templates
which should work in any Windows version.

Once you have a working installation program, try to test it on every
combination of Word version, Windows version, and customization vs. defaults
that you can find.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
K

Karl E. Peterson

Southern said:
I have a Word template to share with others. I repeatedly have to explain
how they need to put it in their template folder before using it. Is there a
simple way to create an .exe file that all it does check to see what the MS
Word uses as the tempate folder and copys my template into it?

Compile this in your favorite version of ClassicVB:

Option Explicit

Public Sub Main()
Dim Word As Object
Dim Msg As String

On Error Resume Next
Set Word = CreateObject("Word.Application")
If Err.Number Then
Msg = "Word Not Installed."
Else
Msg = "Workgroup: " & Word.Options.DefaultFilePath(3) & vbCrLf & _
"User: " & Word.Options.DefaultFilePath(2)
End If
MsgBox Msg, , "Template Paths"
End Sub

Or, just save this as a VBS file, and double-click it:

Option Explicit

Dim Word 'As Object
Dim Msg 'As String

On Error Resume Next
Set Word = CreateObject("Word.Application")
If Err.Number Then
Msg = "Word Not Installed."
Else
Msg = "Word Template Paths" & vbCrLf & _
"=============================================" & vbCrLf & _
"Workgroup: " & Word.Options.DefaultFilePath(3) & vbCrLf & _
"User: " & Word.Options.DefaultFilePath(2)
End If
WScript.Echo Msg

Be aware that emailing people either VBS or EXE files is problematic, and you'll
probably have to ZIP them up or even change the extensions to get throgh the
net-nanny patrols.


Later... Karl
 
K

Karl E. Peterson

Karl said:
Compile this in your favorite version of ClassicVB:

Crud! Forgot one, teensy-weensy, *critical* detail!
Option Explicit

Public Sub Main()
Dim Word As Object
Dim Msg As String

On Error Resume Next
Set Word = CreateObject("Word.Application")
If Err.Number Then
Msg = "Word Not Installed."
Else
Msg = "Workgroup: " & Word.Options.DefaultFilePath(3) & vbCrLf & _
"User: " & Word.Options.DefaultFilePath(2)
End If
MsgBox Msg, , "Template Paths"
Word.Quit '<=======================!!!!!!!!!!!!!!!!!!!!!
End Sub

Or, just save this as a VBS file, and double-click it:

Option Explicit

Dim Word 'As Object
Dim Msg 'As String

On Error Resume Next
Set Word = CreateObject("Word.Application")
If Err.Number Then
Msg = "Word Not Installed."
Else
Msg = "Word Template Paths" & vbCrLf & _
"=============================================" & vbCrLf & _
"Workgroup: " & Word.Options.DefaultFilePath(3) & vbCrLf & _
"User: " & Word.Options.DefaultFilePath(2)
End If
WScript.Echo Msg
Word.Quit '<=======================!!!!!!!!!!!!!!!!!!!!!

Otherwise, you end up with an orphaned instance of WINWORD.EXE running, and need to
kill it using Task Manager.
 
J

Jay Freedman

Easy? No, that would be far too simple for anything named Microsoft. ;-)

The first step is to look in the registry at the key
HKEY_CLASSES_ROOT\Word.Document.8\shell\Open\command
The value of the (Default) item contains the path to the copy of WinWord.exe
that opens a document when you launch it from Windows Explorer. That path
contains the version number of that copy of Word; for example,
"C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE"
tells you that version 11 (that is, Word 2003) is the target.

The next step is to look in the registry at the key
HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Common\General
or the equivalent for whatever version of Office is being targeted. If the
key contains an item named UserTemplates, then the user has customized the
location of the User Templates folder to be different from the installation
default, and the value of the item is the folder where you should install
your template.

If there is no UserTemplates item in the key, then Word is using the
installation default. Unfortunately, that varies by Office version and
Windows version. For recent versions of Word on 32-bit Windows XP, it will
be
C:\Documents and Settings\<user name>\Application Data\Microsoft\Templates
It will be slightly different for 64-bit Windows and for Vista. If you can
expand environment strings in your program, it may be easier to look for
%appdata%\Microsoft\Templates
which should work in any Windows version.

Once you have a working installation program, try to test it on every
combination of Word version, Windows version, and customization vs. defaults
that you can find.

Listen to Karl. I should have thought of the scripting approach, but I was
concentrating too much on the registry in another project and that's where my
thoughts went first.
 
K

Karl E. Peterson

Jay said:
concentrating too much on the registry in another project and that's where my
thoughts went first.

Trees, forest; forest, trees. Yep, btdt2. :)
 
D

Darren Hill

The method below is very helpful to me.
Is it possible to use have the script open the startup folder in explorer,
or paste the address into a word file which is left open? The latter option
would allow copy & paste into the explorer address bar.

Thanks,
Darren
 

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