![]() |
|
#1
|
||||
|
||||
![]()
For example, the following code creates and applies a series of character Styles throughout the document.
Code:
Sub ApplyCharacterStyles() Application.ScreenUpdating = False Dim Rng As Range, i As Long, j As Long, ArrStyl, ArrItal, ArrBold, ArrUlin, bFnd As Boolean ArrStyl = Array("Bold", "Italic", "Underline", "Bold Italic", "Bold Underline", "Italic Underline", "Bold Italic Underline") ArrBold = Array(True, False, False, True, True, False, True) ArrItal = Array(False, True, False, True, False, True, True) ArrUlin = Array(False, False, True, False, True, True, True) With ActiveDocument For i = 0 To UBound(ArrStyl) For j = 1 To .Styles.Count bFnd = (ArrStyl(i) = .Styles(j)): If bFnd = True Then Exit For Next If bFnd = False Then .Styles.Add Name:=ArrStyl(i), Type:=wdStyleTypeCharacter Next For i = 0 To UBound(ArrStyl) With .Styles(ArrStyl(i)).Font .Italic = ArrItal(i) .Bold = ArrBold(i) .Underline = ArrUlin(i) End With Next For Each Rng In .StoryRanges For i = UBound(ArrStyl) To 0 Step -1 With Rng.Duplicate With .Find With .Font .Italic = ArrItal(i) .Bold = ArrBold(i) .Underline = ArrUlin(i) End With End With Do While .Find.Execute = True If .Style <> ArrStyl(i) Then If .Start <> .Paragraphs.First.Range.Start Or .End <> .Paragraphs.Last.Range.End Then .Style = ArrStyl(i) Else With .Paragraphs.First.Range.Style.Font If .Italic <> ArrItal(i) Then If .Bold <> ArrBold(i) Then If .Underline <> ArrUlin(i) Then .Style = ArrStyl(i) End If End If End With End If End If If .Information(wdWithInTable) = True Then If .End = .Cells(1).Range.End - 1 Then .Start = .Cells(1).Range.End If .Information(wdAtEndOfRowMarker) = True Then .Start = .End + 1 End If If .End = Rng.End Then Exit Do .Collapse wdCollapseEnd Loop End With Next Next End With Application.ScreenUpdating = True MsgBox "Finished applying Character Styles" End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#2
|
|||
|
|||
![]()
Is this macro create character styles and change to the character styles
While run its stop in the line Code:
With .Styles(ArrStyl(i)).Font |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Styles: Cannot Apply or Save | Justin | Word | 5 | 11-01-2020 03:20 PM |
Macro to apply Normal dot styles | John9210 | Word VBA | 2 | 06-07-2018 05:15 PM |
Apply styles in word table | 1van | Word VBA | 2 | 11-17-2015 11:05 AM |
search for special character and apply outline? | n00bie-n00b | Word VBA | 0 | 10-12-2014 03:17 AM |
automatically extract footnotes into new file and apply character format to footnote | hrdwa | Word | 0 | 02-27-2010 03:16 AM |