Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-29-2022, 10:33 PM
macropod's Avatar
macropod macropod is offline Create & Apply Character Styles for Export to InDesign Windows 10 Create & Apply Character Styles for Export to InDesign Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #2  
Old 11-29-2022, 10:51 PM
stky stky is offline Create &amp; Apply Character Styles for Export to InDesign Windows 10 Create &amp; Apply Character Styles for Export to InDesign Office 2013
Advanced Beginner
Create &amp; Apply Character Styles for Export to InDesign
 
Join Date: Apr 2021
Posts: 30
stky is on a distinguished road
Default Is this macro create character style

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
Reply With Quote
Reply



Similar Threads
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

Other Forums: Access Forums

All times are GMT -7. The time now is 09:36 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft