Macro to copy styles from Normal

S

Sammy

Hi,

I have the following statement designed to copy the user's styles from their
Normal.dot (we are using roaming profiles) to the current doc, but it doesn't
work. Any ideas on what I can change?

ActiveDocument.CopyStylesFromTemplate Template:= _
"%appdata%\microsoft\templates\Normal.dot"


Our path to each user's Normal.dot is the following:

'C:\Documents and Settings\shcha\Application Data\Microsoft\Templates

THANK YOU!
 
N

NZ VBA Developer

Sammy,

Although the VBA help identifies 'NormalTemplate' as a property of the
Application object, it also behaves like a template object. (Search the help
for 'normal template' and note that the help gives an example of using the
Save method with NormalTemplate.) This means you can use it with the
CopyStylesFromTemplate method as follows:

ActiveDocument.CopyStylesFromTemplate NormalTemplate

Word 'knows' where the normal template is, so you don't have to worry about
identifying its location.

BTW, as you probably know, the CopyStylesFromTemplate method copies _all_ of
the styles from the source template. If you want to copy only specific styles
from a template, you'll have to use a difference process. And as I found out
the hard way some years back, the OrganizerCopy method has bugs in it. (It
doesn't bloody work!) Consequently, you have to iterate through all of the
styles in the source template and copy them across individually.

Also be aware that the CopyStylesFromTemplate method may not work perfectly,
especially for if a style has numbering. It seems that Word uses a bit of a
shortcut (ListTemplate objects) when defining numbering, and if a user has
customised a list format it may cause a problem as CopyStylesFromTemplate
doesn't copy the ListTemplates. The solution is to make sure you define the
format for the ListTemplate(s) used by any styles prior to copying the styles
in from the source template. I have code for doing this but it's a bit too
complicated to post here - assuming that you're interested...

Cheers!
 
O

old man

Hi,

You are confusing Environment variables (and DOS Commands) where what you
are doing would work with VBA.

In VBA you can try something like this:

startpath = environ("appdata")
if len(startpath)> 0 then
wholepath = startpath & "\microsoft\templates\Normal.dot"
endif

Old Man
 
N

NZ VBA Developer

G'day Sammy,

Like I said, the process is complicated and probably too much to post in the
forum. In addition, it's been awhile since I worked with this bit of code,
but I've got another project coming up soon that will require me to revisit
it. However, your query has stimulated me to do so now - in preparation for
the upcoming job. I don't imagine you'll want to try to plow through all the
intervening posts looking for my answer when I finally do get it sorted, so
perhaps you'd like to contact me via email and I'll send you a brain dump
once I've refreshed my knowledge. I'd rather not give my email address to the
spammers, but I'm sure you'll be able to decipher this:
gordon(dot)bentleymix(at)gmail(dot)com.

Cheers!
 

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