Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy Word style definition

Status
Not open for further replies.

JBU

Instructor
Nov 3, 2003
25
IN
Hi

I want to copy the definition of a Word Style to another style, so that their appearance will be identical. I have names of the two styles, but I don't know where to go from there. The obvious:

ActiveDocument.styles("Style1")=ActiveDocument.styles("Style2")

obviously doesn't work :)

Any help would be appreciated.

Jens Busse
Workflow Consultant
CCI Europe A/S
 
Hi Jens,

One way would be to create a new style based on the existing one, as in:
Code:
Sub ReplicateStyle()
ActiveDocument.Styles.Add Name:="Style2", Type:=wdStyleTypeParagraph
    With ActiveDocument.Styles("Style2")
        .AutomaticallyUpdate = False
        .BaseStyle = "Style1"
        .NextParagraphStyle = "Normal" 'or whatever you want
    End With
End Sub
Since Style2 takes its formatting from Style1, any subsequent changes to Style1 will impact Style2.

Cheers

[MS MVP - Word]
 
Hi

I think I've found what I needed. I had to copy the different parts of style one by one. In other words something like:

ActiveDocument.styles("Style1").font = ActiveDocument.styles("Style2").font

etc.

Macropod: Your approach unfortunately didn't work in my case, since the style already existed and could be in use. Thanks anyway.


Jens Busse
Workflow Consultant
CCI Europe A/S
 
Hi Jens,

In that case:
Code:
Sub ReplicateStyle()
Dim Sty As Style
Dim StyExists As Boolean
Dim BaseSty As String
Dim NewSty As String
With ActiveDocument
    BaseSty = "Style1"
    NewSty = "Style2"
    StyExists = False
    For Each Sty In .Styles
        If Sty = NewSty Then StyExists = True
    Next
    If StyExists = False Then .Styles.Add Name:=NewSty, Type:=wdStyleTypeParagraph
    With .Styles(NewSty)
        .BaseStyle = BaseSty
    End With
End With
End Sub
No need to update the style one parameter at a time.

Cheers

[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top