IF THEN to test if style exists, if not, to create

K

kurt

Mistake on my last post...

Here is my code:

If ActiveDocument.Styles("Block Text 2").InUse = True Then


Selection.Style = ActiveDocument.Styles("Block Text 2")
Else
ActiveDocument.Styles.Add Name:="Block Text 2", Type:=wdStyleTypeParagraph
ActiveDocument.Styles("Block Text 2").AutomaticallyUpdate = False
With ActiveDocument.Styles("Block Text 2").Font
.Name = "Times New Roman"
.Size = 12
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorAutomatic
.Engrave = False
.Superscript = False
.Subscript = False
.Scaling = 100
.Kerning = 0
.Animation = wdAnimationNone
End With
With ActiveDocument.Styles("Block Text 2").ParagraphFormat
.LeftIndent = InchesToPoints(0)
.RightIndent = InchesToPoints(0)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 12
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphJustify
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = InchesToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
ActiveDocument.Styles("Block Text
2").NoSpaceBetweenParagraphsOfSameStyle _
= False
ActiveDocument.Styles("Block Text 2").ParagraphFormat.TabStops.ClearAll
With ActiveDocument.Styles("Block Text 2").ParagraphFormat
With .Shading
.Texture = wdTextureNone
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor = wdColorAutomatic
End With
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
With .Borders
.DistanceFromTop = 1
.DistanceFromLeft = 4
.DistanceFromBottom = 1
.DistanceFromRight = 4
.Shadow = False
End With
End With
ActiveDocument.Styles("Block Text 2").LanguageID = wdEnglishUS
ActiveDocument.Styles("Block Text 2").NoProofing = False
ActiveDocument.Styles("Block Text 2").Frame.Delete
Selection.Style = ActiveDocument.Styles("Block Text 2")

End If

End Sub

The If statement works alone, the Else statement works alone, but not
together. In other words, if the Block Text 2 style is not found to be
available (whether it's in use or not), the macro fails to create it.

THANKS for all help!

Kurt
 

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