Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2007

Tip: Looking for answers? Try searching our database.

Macro to copy styles from Normal

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sammy - 25 Jul 2007 21:46 GMT
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!
NZ VBA Developer - 25 Jul 2007 23:06 GMT
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!

> Hi,
>
[quoted text clipped - 10 lines]
>
> THANK YOU!
Sammy - 26 Jul 2007 17:58 GMT
I AM INTERESTED IN ANYTHING YOU HAVE TO SAY.  THANKS FOR YOUR HELP

> Sammy,
>
[quoted text clipped - 41 lines]
> >
> > THANK YOU!
NZ VBA Developer - 26 Jul 2007 23:08 GMT
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!

> I AM INTERESTED IN ANYTHING YOU HAVE TO SAY.  THANKS FOR YOUR HELP
>
[quoted text clipped - 43 lines]
> > >
> > > THANK YOU!
old man - 25 Jul 2007 23:10 GMT
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

> Hi,
>
[quoted text clipped - 10 lines]
>
> THANK YOU!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.