New document from template - Macro code help needed

M

Marley

Using Word 2007and customising the ribbon I can create a macro and button
which then opens a new document from this template. However I want to put in
code which picks up the user's own name:

This works for me:
Documents.Add
("C:\Users\joebloggs\AppData\Roaming\Microsoft\Templates\Synapsys\Report.dotm")

But I want to change the 'joebloggs' to automatically pick up the user name
of whoever logs on but this is beyond my simple skills.

Cheers for the help!
 
J

Jay Freedman

Use the expression

Options.DefaultFilePath(wdUserTemplatesPath)

to replace the part of the path up to and including "Templates", and tack on the
rest of the path and the filename:

Documents.Add(Options.DefaultFilePath(wdUserTemplatesPath) & _
"\Synapsys\Report.dotm")

Note that the result of the function does not include a backslash at the end, so
you need to include it in the additional part.

Also, using the function will automatically take care of anyone who's running on
Windows XP, where the equivalent path would be
C:\Documents and Settings\joebloggs\Application Data\Microsoft\Templates....

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

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