Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
LaurenNichole said:I guess the real question is "can I programmatically apply a style to text that has never had a style applied before?"
Sub TestSelection()
Selection.Style = "TestStyle"
End Sub
Sub TestRange()
Dim oRange As Word.Range
Set oRange = ActiveDocument.Paragraphs(7).Range
oRange.Style = "teststyle"
Set oRange = Nothing
End Sub
Sub TestParagraph()
Dim oPara As Word.Paragraph
Set oPara = ActiveDocument.Paragraphs(4)
oPara.Style = "TestStyle"
Set oPara = Nothing
End Sub
Sub TestStyleArray()
Dim myStyles(2) As String
Dim var
myStyles(0) = "TestStyle"
myStyles(1) = "TestStyle2"
myStyles(2) = "TestStyle3"
For var = 0 To 2
ActiveDocument.Paragraphs(var + 1).Style = myStyles(var)
Next
End Sub
I want to be able to go through the whole document and according to what is already there I want to assign a name to the style.
Sub eachParagraph()
Dim oPara As Word.Paragraph
For Each oPara In ActiveDocument.Range.Paragraphs()
If oPara.Style = "para4" Then
MsgBox "Yup para4"
End If
If oPara.Range.Font.Bold = True Then
MsgBox "Yeah....this paragraph is bolded...so what?"
End If
Next
End Sub
If oPara.Range.Font.Name = "Arial" And _
oPara.Range.Font.Bold = False And _
oPara.Range.Font.Italic = False And _
oPara.Range.Font.Underline = wdUnderlineNone And _
oPara.Range.Font.UnderlineColor = wdColorAutomatic And _
oPara.Range.Font.StrikeThrough = False And _
oPara.Range.Font.DoubleStrikeThrough = False And _
oPara.Range.Font.Outline = False And _
oPara.Range.Font.Emboss = False And _
oPara.Range.Font.Shadow = False And _
oPara.Range.Font.Hidden = False And _
oPara.Range.Font.SmallCaps = False And _
oPara.Range.Font.AllCaps = False Then
oPara.Range.Style = "Style1"
' blah blah
With ActiveDocument.Styles("BrandNewStyle").Font
.Name = "Charlesworth"
.Size = 9
.Bold = False
.Italic = True
.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("BrandNewStyle").ParagraphFormat
.LeftIndent = InchesToPoints(0)
.RightIndent = InchesToPoints(0)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.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("BrandNewStyle").NoSpaceBetweenParagraphsOfSameStyle _
= False
ActiveDocument.Styles("BrandNewStyle").ParagraphFormat.TabStops.ClearAll
With ActiveDocument.Styles("BrandNewStyle").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("BrandNewStyle").LanguageID = wdEnglishUS
ActiveDocument.Styles("BrandNewStyle").NoProofing = False
ActiveDocument.Styles("BrandNewStyle").Frame.Delete
Sub CreateStyleCurrentParagraph()
Dim trStyleName As String
strStyleName = InputBox("Name of new style?")
If Selection.Information <> wdSelectionIP Then
Selection.Collapse Direction:=wdCollapseStart
With ActiveDocument
.Styles.Add Name:=strStyleName, _
Type:= wdStyleTypeParagraph
.Styles(strStyleName) _
.AutomaticallyUpdate = False
End With
Else
With ActiveDocument
.Styles.Add Name:=strStyleName, _
Type:= wdStyleTypeParagraph
.Styles(strStyleName) _
.AutomaticallyUpdate = False
End With
End If