Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
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
  #2  
Old 09-16-2021, 02:31 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 Andrew, thank you so much for your reply and the code. I've run the code on my 200 page document and the following happens:

If fields that are already formatted unbold and italics remain correctly formatted, the code does not change these which is brilliant.

Adding new fields within brackets just formats them unbold and not italics so this needs to change to italics.

I'm not sure what to change to correct this.

Shelley
Reply With Quote
Reply



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 04:18 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