View Single Post
 
Old 03-17-2024, 02:24 AM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,166
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

This code works for me and shows how you might do it with your custom styles. I've used built-in styles for illustrating the method. Note that VBA considers '{020)' to be three words which is why the code applies the last character style to the first three words.
Code:
Sub FormatPara()
  Dim aPar As Paragraph, aRng As Range
  Set aPar = Selection.Paragraphs(1)
  With aPar
    .Style = "Body Text"      'Apply a paragraph style to the entire paragraph
    .Range.Sentences(1).Style = "Emphasis"    'Apply a character style to the first sentence
    Set aRng = .Range.Words(3)        'Define a Range for the third 'word'
    aRng.Start = .Range.Start         'Extend that range to the start of the paragraph
    aRng.Style = "Strong"             'Style the range
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote