A Global StyleSheet in Microsoft WordGlobal Templates work very well for sharing most kinds of customizations in Word. The big exception is styles. Styles contained in global templates are ignored by documents. A macro, though, can be used to copy styles from a global template to the active document. What follows is such a macro to copy the style Body Text and Heading Styles 1-9 from a global template to the active document. If there is no document open, it will generate a message box. Before copying the styles, the macro asks whether the person is sure that he/she wants to redefine the styles. If "yes", then it will copy the styles using the Organizer. If no, it exits.
Sub StyleCopyMacro()
'
' StyleCopy Macro written by Charles Kyle Kenyon 14 November 2001
' Copyright 2001 All rights reserved
' Copies styles from stylesheet global template to active document
'
' Declare variables
Dim sThisTemplate As String
Dim sTargetDoc As String
Dim i As Integer ' Counter 1 - use for copying styles three times
Dim iCount As Integer ' Counter 2 - use to loop copying of heading styles
Dim rResponse As Variant ' can be vbMsgBoxResult in Word 2000 or later
' Error Handler set
On Error GoTo NoDocument ' Call when no document is open.
' Define This Template and Target Document variables
sThisTemplate = ThisDocument.FullName ' name and path of global template
sTargetDoc = ActiveDocument.FullName 'generates error if no document open
' If any other errors, continue on
On Error Resume Next
rResponse = MsgBox(Prompt:="This command redefines your Body Text Style and" _
& vbCrLf & "Heading Styles 1-9. Are you sure you want to do this?" _
& vbCrLf & vbCrLf & "If you are not sure, answer 'No' and make a backup of your document." _
& vbCrLf & "Then run the command to copy the styles again.", _
Title:="Are you sure you want to redefine your styles?", _
Buttons:=vbYesNo + vbExclamation)
If rResponse = vbNo Then Exit Sub
' Copy Body Text and Heading Styles to Active Document
' Note that this requires exact style names
For i = 1 To 3 ' copy styles three times to maintain linkages
With Application
.OrganizerCopy Source:=sThisTemplate, _
Destination:=sTargetDoc, Name:="Body Text", Object:= _
wdOrganizerObjectStyles
For iCount = 1 To 9 'Copy heading styles 1-9
.OrganizerCopy Source:=sThisTemplate, _
Destination:=sTargetDoc, Name:= _
"Heading " & iCount, _
Object:=wdOrganizerObjectStyles
Next iCount
End With
Next i
Exit Sub ' Skip error handler routine
NoDocument: ' Error Handler - Will be called if there is not an open document
MsgBox Prompt:="Sorry, this command is only available when you have a document open.", _
Title:="No document open!", Buttons:=vbExclamation
End Sub
End of procedure (macro). (I didn't say it would be easy, just that it could be done!) For instructions on copying this macro into your template, see Macros and VBA. Additional Thoughts
See Understanding Styles in Microsoft Word for more on styles. You may also want to take a look at the StyleRef Field Tutorial, the IncludeText Field Tutorial, and the Letterhead Textboxes and Styles Tutorial for a better idea of how styles can interact with each other. Paul Edstein posted a macro on the Windows Secrets Lounge 2013 that copies all styles used in text in a document to all open documents. This could easily be adapted to use in a global stylesheet as well. |
|
Many people visit this site and use the information it
contains.
Copyright 2000-2013 Charles Kyle Kenyon
FAQ provided as an adjunct / hobby as a part of my web site as a
criminal defense lawyer.
|