View Single Post
 
Old 09-15-2021, 09:01 AM
Shelley Lou Shelley Lou is offline Windows 10 Office 2016
Competent Performer
 
Join Date: Dec 2020
Posts: 170
Shelley Lou is on a distinguished road
Default VBA Formatting Fields within parentheses

Hi, I have created the code below to format fields within brackets that appear directly after references to clauses (the fields contain the heading to the clause). The format for these fields should be italics and not bold. The code works but when run it also removes the bold formatting from the numbering fields for Schedule and Part (see page 2). Can anyone help me tweak the code below to not change the schedule/part numbering fields and only change the fields within the brackets. By way of reference the text fields after clauses are inserted via Cross Reference Paragraph Text. Thanks

Field Test macro.docx

Code:
Sub DPU_Banking_HeadingsInBrackets()
Application.ScreenUpdating = False
Dim Para As Paragraph, oRng As Range
ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
Set oRng = ActiveDocument.Range
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = " \* MERGEFORMAT "
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll
End With
With oRng.Find
.Replacement.Font.Bold = False
.Text = "^d"
.Replacement.Text = "^&"
.Format = True
.Execute Replace:=wdReplaceAll
End With
With oRng.Find
.Replacement.Font.Italic = True
.Text = "(^d"
.Replacement.Text = "^&"
.Wrap = wdFindContinue
.Format = True
.Execute Replace:=wdReplaceAll
End With
With oRng.Find.Replacement.Font
.Bold = False
.Italic = False
End With
With Selection.Find
.Text = " \h "
.Replacement.Text = "^& \* Charformat "
.Format = True
.Execute Replace:=wdReplaceAll
End With
With oRng.Find
.Text = "("
.Replacement.Text = "("
.Format = True
.Execute Replace:=wdReplaceAll
End With
ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
Application.ScreenUpdating = True
End Sub
Reply With Quote