Copying a style object to make a new one

G

Garry

Hi All:

I'm missing something obvious.

I want to create a new style by copying an existing one and making a
few mods, the equivalent to using the "Based On" field in the styles
dialog. After thinking about Set statements and the like, I'm confused
as to how to go about this. Just how does one copy an object?

Garry
 
G

Greg Maxey

Something like:

Sub Scratch()
Dim style As Style
Set style = Active.Styles.Add("YourNewStyleName")
With oStyle
.BaseStyle = ActiveDocument.Styles("Normal")
.Font.Bold = True
.ParagraphFormat.LineSpacing = 24
End With
End Sub
 
K

Klaus Linke

Hi Garry,

There's no "clean" way in VBA to copy a style, AFAIK. You just use .Add to
create a new one, and set ".BasedOn" to the existing one.
As in the user interface, the newly added style will pick up any manual
(font/paragraph) formatting from the start of the current selection, so
you'd either need to make sure that none is applied, or (re)set all the
formatting to that of the base style.

Regards,
Klaus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top