It could also be called as part of the AutoNew macro in particular document templates to pull in or refresh styles in It is expected that the macro would be attached to a QAT icon (Word 2007+) orĪ menu command (Word 2003 and earlier) in the This would have the advantage of being able to have multiple style sets Then use the Organizer to copy styles from that stylesheet. Predetermined place on the system, possibly in a folder in the Workgroup AnĪlternative to Table styles is the use ofĪn alternative would be to have a separate stylesheet residing in a Transfer numbering attached to styles although not the list style, itself. Not hold or transfer numbering or Table styles. These should make unnecessary the use of the macro in a global templateįor most styles. Ribbon versions of Word also have the ability to use The best place for styles is in the document template rather than in a (I didn't say it would be easy, just that itįor instructions on copying this macro into your own template, see Macros and VBAĪlready has it installed. Title:="No document open!", Buttons:=vbExclamationĮnd of procedure (macro). MsgBox Prompt:="Sorry, this command is only available when you have a document open.", _
' Note that this requires exact style namesįor i = 1 To 3 ' copy styles three times to maintain linkages With Applicationĭestination:=sTargetDoc, Name:="Body Text", Object:= _įor iCount = 1 To 9 'Copy heading styles 1-9 If rResponse = vbNo Then Exit Sub ' Copy Body Text and Heading Styles to Active Document & vbCrLf & "Then run the command to copy the styles again.", _ & vbCrLf & vbCrLf & "If you are not sure, answer 'No' and make a backup of your document." _ RResponse = MsgBox(Prompt:="This command redefines your Body Text Style and" _ STargetDoc = ActiveDocument.FullName 'generates error if no document open ' If any other errors, continue on On Error Resume Next SThisTemplate = ThisDocument.FullName ' name and path of global template ' Define This Template and Target Document variables On Error GoTo NoDocument ' Call when no document is open. ' 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 ' Copies select styles from stylesheet global template to active document ' StyleCopy Macro written by Charles Kyle Kenyon 14 November 2001 If "yes", then it will copy the styles using This uses the OrganizerCopyīefore copying the styles, the macro asks whether the person is sure that If there is noĭocument open, it will generate a message box. Heading Styles 1-9 from a global template to the active document. What follows is a more elaborate macro to copy the style Body Text and Title:="No document open!", buttons:=vbExclamation MsgBox Prompt:="Sorry, this command is only available when you have a NoDocument: ' Error Handler - Will be called if there is not an open document MsgBox Prompt:="The styles from " & ThisDocument.Name & " have been copied to your document."
How to copy heading styles in word 2013 code#
' ThisDocument is the holder of the code as well as the stylesįor i = 1 To 3 ' copy styles three times to maintain linkagesĪctiveDocument.CopyStylesFromTemplate (ThisDocument.FullName) ' Copy all styles from this template to all to Active Document Title:="Are you sure you want to redefine your styles?", _ & vbCrLf & "Then run the command to copy the styles again.", & vbCrLf & vbCrLf & "If you are not sure, answer 'No' and & vbCrLf & "Are you sure you want to do this?" _ RResponse = MsgBox(Prompt:="This command redefines your document's ' Check to see if user really wants to do it. On Error GoTo NoDocument 'In case called when no document is open. ' Copies all styles from stylesheet global template to active documentĭim rResponse As Variant 'vbMsgBoxResult in Word 2000 or later ' Copyright 2001, 2020 All rights reserved ' StylesCopyAll Macro written by Charles Kyle Kenyon 14 November 2001 revised 12 What follows is first a macro to copy all styles from a global template to A sample global stylesheet template with this macro can be Styles contained in global templates areĪ macro, though, can be used to copy styles from a global template to theĪctive document. Global Templates work very well for sharing most kinds of customizations in List and other info and go directly to the start of this topic. Please consider making a donation if you can. It costs money to keep on line and effort to