Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 09-15-2021, 08:36 PM
Guessed's Avatar
Guessed Guessed is offline VBA Formatting Fields within parentheses Windows 10 VBA Formatting Fields within parentheses Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
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

I wouldn't do this with search and replace. Try this code as an alternative
Code:
Sub SetFieldFormat()
  Dim aFld As Field, sCode As String
  For Each aFld In ActiveDocument.Fields
    sCode = LCase(aFld.Code)
    If sCode Like "* ref *" Then
      Debug.Print sCode
      If Not sCode Like "*\w*" Then
        aFld.Result.Font.Italic = True
        aFld.Result.Font.Bold = False
        If sCode Like "*mergeformat*" Then
          sCode = Replace(sCode, "merge", "char")
        ElseIf Not sCode Like "*charformat*" Then
          sCode = sCode & " \* charformat "
          aFld.Code.Text = sCode
        End If
        aFld.Update
      End If
    End If
  Next aFld
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
 

Thread Tools
Display Modes


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 07:49 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