View Single Post
 
Old 09-07-2018, 02:19 PM
jeffreybrown jeffreybrown is offline Windows Vista Office 2007
Expert
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default

So apparently I don't understand the parts in blue. This code is applying the character styles to the commas also. I thought the parts in blue were formatting the commas also, but apparently not.

1) How can I stop the commas from retaining the character styles applied by the code?
2) How can the code skip the paragraph if the number of commas does not equal two?

Before
AFC 39-101, A Reference book, 23 August 2018
DAB 10-211, Automotive Manual, 16 January 2009
XYZ 39-101, Instruction cards
XYZ 39-101, Volume 1, Instruction cards, 23 December 2015

After
AFC 39-101, A Reference book, 23 August 2018
DAB 10-211, Automotive Manual, 16 January 2009
XYZ 39-101, Instruction cards (no format < 2 commas)
XYZ 39-101, Volume 1, Instruction cards, 23 December 2015 (no format > 2 commas)

Code:
Sub FormatReferencePara()
    Dim oPara   As Paragraph
    Dim oRng    As Range
    Dim oSel    As Range
    Set oSel = Selection.Range
    For Each oPara In oSel.Paragraphs
        Set oRng = oPara.Range
        oRng.Collapse 1
        oRng.MoveEndUntil Chr(44)
        oRng.End = oRng.End + 1
        oRng.Style = "Strong"
        oRng.Collapse 0
        oRng.MoveEndUntil Chr(44)
        oRng.End = oRng.End + 1
        oRng.Style = "Subtle Emphasis"
        oSel.Select
    Next oPara
lbl_Exit:
    Set oRng = Nothing
    Set oSel = Nothing
    Exit Sub
End Sub
Reply With Quote