|
| View previous topic :: View next topic |
| Author |
Message |
mikewillnot Guest
|
Posted: Fri Nov 09, 2007 6:45 pm Post subject: code to copy style from one template to active doc template |
|
|
With Word 2003, I have a customized Comment Text style in my
normal.dot template that I'd like to use in every document I open.
The only way I can see to make that happen is by manually copying the
style, using the organizer, from normal.dot to the active document.
I'd like to automate this. I used Macro Recorder, and get the code
below, but it only works on this particular open document. I tried
adjusting it to copy to whatever the activedocument is, but couldn't
get anything to work. Any suggestions would be greatly appreciated.
THANKS.
Sub aaa__copy_style_to_activedoc()
'
With ActiveDocument
.UpdateStylesOnOpen = False
.AttachedTemplate = "Normal"
.XMLSchemaReferences.AutomaticValidation = True
.XMLSchemaReferences.AllowSaveAsXMLWithoutValidation = False
End With
Application.OrganizerCopy Source:= _
"C:\Documents and Settings\williamsmi\Application Data
\Microsoft\Templates\Normal.dot" _
, Destination:= _
"[filepathandname]" _
, Name:="Comment Text", Object:=wdOrganizerObjectStyles
End Sub |
|
| Back to top |
|
 |
Google Sponsor

|
Posted: Fri Nov 09, 2007 6:45 pm Post subject: Advertisement |
|
|
|
|
| Back to top |
|
 |
Shauna Kelly Guest
|
Posted: Sat Nov 10, 2007 2:16 am Post subject: Re: code to copy style from one template to active doc templ |
|
|
Hi
Here's your existing code, commented to explain what it's actually doing and
what might cause problems, and a replacement macro:
Sub aaa__copy_style_to_activedoc()
With ActiveDocument
'Make sure we don't update styles when we open this document.
'This should not be necessary, although it can't hurt.
.UpdateStylesOnOpen = False
'Attach the Normal template to this document. Probably
'not what you want
.AttachedTemplate = "Normal"
'Set automatic validation on all XMLSchemas.
'Do you have an XMLSchema attached to every document on
'which you run this document? Probably not, so we don't
'want this line.
.XMLSchemaReferences.AutomaticValidation = True
'Tell Word that you can only save the document if
'it validates against any XML schema. Probably not something
'you want to enforce when you just want to copy a style.
'So we don't need this.
.XMLSchemaReferences.AllowSaveAsXMLWithoutValidation = False
End With
'I've re-arranged this to make it easier to read.
'But....
'You don't necessarily have a "normal.dot" file. If you had a new
'installation, Word only creates the file when it needs to.
'However, Word has a property named NormalTemplate that will work
'whether or not the actual Normal.dot file has been created.
'
'And, this will crash if for some reason your normal template
'has no style named Comment Text
Application.OrganizerCopy _
Source:="C:\Documents and Settings\williamsmi\Application
Data\Microsoft\Templates\Normal.dot", _
Destination:="[filepathandname]", _
Name:="Comment Text", _
Object:=wdOrganizerObjectStyles
End Sub
Sub CopyCommentTextStyleToActiveDocument()
'Avoid an error message if for some reason your
'NormalTemplate does not have a style named
'"Comment Text"
On Error Resume Next
'Copy the Comment Text style from the Normal
'template to the active document
Application.OrganizerCopy _
Source:=NormalTemplate, _
Destination:=ActiveDocument.FullName, _
Name:="Comment Text", _
Object:=wdOrganizerObjectStyles
End Sub
Hope this helps.
Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
"mikewillnot" <mikewill4@gmail.com> wrote in message
news:1194633919.594748.87740@o38g2000hse.googlegroups.com...
| Quote: | With Word 2003, I have a customized Comment Text style in my
normal.dot template that I'd like to use in every document I open.
The only way I can see to make that happen is by manually copying the
style, using the organizer, from normal.dot to the active document.
I'd like to automate this. I used Macro Recorder, and get the code
below, but it only works on this particular open document. I tried
adjusting it to copy to whatever the activedocument is, but couldn't
get anything to work. Any suggestions would be greatly appreciated.
THANKS.
Sub aaa__copy_style_to_activedoc()
'
With ActiveDocument
.UpdateStylesOnOpen = False
.AttachedTemplate = "Normal"
.XMLSchemaReferences.AutomaticValidation = True
.XMLSchemaReferences.AllowSaveAsXMLWithoutValidation = False
End With
Application.OrganizerCopy Source:= _
"C:\Documents and Settings\williamsmi\Application Data
\Microsoft\Templates\Normal.dot" _
, Destination:= _
"[filepathandname]" _
, Name:="Comment Text", Object:=wdOrganizerObjectStyles
End Sub
|
|
|
| Back to top |
|
 |
mikewillnot Guest
|
Posted: Sat Nov 10, 2007 8:12 pm Post subject: Re: code to copy style from one template to active doc templ |
|
|
This is outstanding. Thank you very much, Shauna, for the excellent
advice and feedback, Your code, of course, worked like a charm. The
explanations, however, were even more helpful. Thanks again. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|