Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #9  
Old 09-17-2021, 09:36 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

Andrew, I think I've fixed the problem with the italics, it still debugs on one of my testing documents but I can live with that for that particular document, I just added aFld.Code.Italic = True and it now works

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
          aFld.Code.Italic = True
        End If
        aFld.Update
      End If
    End If
  Next aFld
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 09:38 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