Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 09-15-2021, 09:01 AM
Shelley Lou Shelley Lou is offline VBA Formatting Fields within parentheses Windows 10 VBA Formatting Fields within parentheses Office 2016
Expert
VBA Formatting Fields within parentheses
 
Join Date: Dec 2020
Posts: 259
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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Extract numbers from parentheses and add them up pokeyarw Excel 9 05-06-2019 09:50 PM
add parentheses to a letter steve8778 Word 6 11-17-2016 07:50 AM
VBA Formatting Fields within parentheses Allignment of numbers with parentheses RussBell Mail Merge 2 10-28-2016 05:51 AM
VBA Formatting Fields within parentheses Parentheses Changing on Document Subject1157 Word 2 06-16-2011 08:46 PM
Problem With Formatting Mailmerge Fields revans611 Mail Merge 0 05-31-2009 06:20 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:10 AM.


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