![]() |
|
#1
|
|||
|
|||
![]()
I have some code that will format text within brackets to italics. I would like to modify the code to look for text in brackets only if they appear after a cross reference field or a cross reference manual number after clause, paragraph, part or schedule and format with italics. What do I need to add to the code to achieve this? Any advice would be very much appreciated.
Before Image.JPG After Image.JPG Cross Ref in Brackets Test.docx Code:
Sub DPU_BracketText_Italics() Dim oRng As Range Set oRng = ActiveDocument.Content With oRng.Find .ClearFormatting .text = "\(*\)" .Font.Bold = False .Forward = True .Wrap = wdFindStop .MatchWildcards = True .Format = True Do While .Execute With oRng .MoveEnd Unit:=wdCharacter, count:=-1 .MoveStart Unit:=wdCharacter, count:=1 .Font.Italic = True .Font.Bold = False .Collapse wdCollapseEnd End With Loop End With End Sub |
#2
|
||||
|
||||
![]()
For example:
Code:
Sub DPU_BracketText_Italics() Application.ScreenUpdating = False With ActiveDocument.Range With .Find .ClearFormatting .Text = " \(*\)" .Forward = True .Wrap = wdFindStop .MatchWildcards = True End With Do While .Find.Execute If .Characters.First.Previous.Fields.Count > 0 Then .Start = .Start + 2 .End = .End - 1 .Font.Italic = True End If .Collapse wdCollapseEnd Loop End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
Hi Macropod, thank you so much for this it is very much appreciated - only tested on one document so far but seems to be working as it should.
|
#4
|
|||
|
|||
![]()
I marked this thread as solved but on further testing, the code isn't working as expected. I ran it on a document containing text within brackets after cross reference fields and general text in brackets. The code formats all text within brackets to italics and not just the text in brackets after a cross reference field. Any advice what I can add to the code to prevent the code from formatting all text within brackets to italics?
Capture.JPG |
#5
|
||||
|
||||
![]()
Hi Shelley,
The only way the macro will italicize the text between a pair of brackets is if they're preceded by a field. I can only conclude that the problem text was either: • preceded by a field when the macro was run and the field was deleted/moved afterwards; or • italicized by some other process.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
janiceward | Word | 3 | 05-06-2016 02:51 PM |
![]() |
spunkygirl1983 | Word | 1 | 03-18-2016 03:42 PM |
Convert manual cross references in footnotes to other footnotes to automatic cross references | ghumdinger | Word VBA | 7 | 11-20-2014 11:47 PM |
![]() |
estube | Word | 1 | 07-08-2014 03:21 AM |
![]() |
Richard B | Word | 3 | 09-11-2013 07:18 AM |