Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-16-2021, 04:09 AM
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,185
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

How about we identify the fields in a different way and use the Character style that makes it italic.
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 aFld.Result.Words.First.Previous = "(" Then
        Debug.Print aFld.Result.Words.First.Previous
        If sCode Like "*mergeformat*" Then
          sCode = Replace(sCode, "mergefield", "charfield")
        ElseIf Not sCode Like "*charformat*" Then
          sCode = sCode & " \* charformat "
          aFld.Code.Text = sCode
        End If
        aFld.Result.Style = "Emphasis"
        aFld.Update
      End If
    End If
  Next aFld
End Sub

__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #2  
Old 09-16-2021, 09:33 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, unfortunately that didn't work, on one document the code wouldn't even run. I've checked the toggle codes on 3 documents, there seems to be both \r and \w
field codes.PNG

When inserting the style Emphasis I get a debug and it changes the clause cross reference number to italics
debug.PNG

I will keep trying
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 10:37 PM.


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