#1
|
|||
|
|||
How to find CAPITALIZED names and change them into small caps
Dear all,
I'm correcting a manuscript of 7650 pages in Word before I import it in InDesign. References to persons are consistenlty written down like this: FERNANDEZ Ferdinand DE SMEDT Floris LA CROIX-FLAGEY Marcelle COMTESSE DE FLANDRE Marie I need to find a way to script a comma (,) after 1, 2 or 3 capitalized parts of names. Next to that, I want to have the (hard) ALL CAPS to appear in SMALL CAPS FERNANDEZ, Ferdinand DE SMEDT, Floris LA CROIX-FLAGEY, Marcelle COMTESSE DE FLANDRE, Marie Is this something that can be done in Word? Thanks in advance, All the best, Dylan |
#2
|
||||
|
||||
You could do that with a macro like:
Code:
Sub Demo() Application.ScreenUpdating = False With ActiveDocument.Range With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "<[A-Z]{2,3} [A-Z]{2,}>" .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchWildcards = True .Execute End With Do While .Find.Found .Case = wdTitleWord .Font.SmallCaps = True .Collapse wdCollapseEnd .Find.Execute Loop End With With ActiveDocument.Range With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "<[A-Z\-]{4,}>" .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchWildcards = True .Execute End With Do While .Find.Found .Case = wdTitleWord .Font.SmallCaps = True .Collapse wdCollapseEnd .Find.Execute Loop End With Application.ScreenUpdating = True End Sub For PC macro installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm For Mac macro installation & usage instructions, see: http://word.mvps.org/Mac/InstallMacro.html
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Dear Paul Edstein,
The macro runs a mistake in my case unfortunately. (Error 5825) I'm not familiar with VBA and writing scripts. Thanks in advance. Cheers, Dylan |
#4
|
||||
|
||||
The error you're seeing with the code is most likely due to your system using non-English regional settings. You should be able to resolve that by changing:
"<[A-Z]{2,3} [A-Z]{2,}>" to: "<[A-Z]{2;3} [A-Z]{2;}>" and changing: "<[A-Z\-]{4,}>" to: "<[A-Z\-]{4;}>"
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
It does work now! Thank you very much.
At first sight it didn't change the acronyms, which is good. Is there a way to modify this script for the acronyms in the body text so they will appear also in SMALL CAPS like this and not like this SMALL CAPS Thanks in advance. All the best, Dylan |
#6
|
||||
|
||||
As the code doesn't affect 2-letter or 3-letter acronyms, you shouldn't be getting any appearing as SMALL CAPS - unless they're already formatted that way.
Assuming they're just ordinary caps, the following code should work: Code:
Sub Demo() Application.ScreenUpdating = False With ActiveDocument.Range With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "<[A-Z]{2;3}>" .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchWildcards = True .Execute End With Do While .Find.Found .Text = LCase(.Text) .Font.SmallCaps = True .Collapse wdCollapseEnd .Find.Execute Loop End With With ActiveDocument.Range With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "<[a-z]{2;3} " .Font.SmallCaps = True .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchWildcards = True .Execute End With Do While .Find.Found If UCase(.Words.Last.Next) = .Words.Last.Next Then .Text = UCase(.Text) .Font.SmallCaps = False End If .Collapse wdCollapseEnd .Find.Execute Loop End With With ActiveDocument.Range With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "<[A-Z]{2;3} [A-Z]{2;}>" .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchWildcards = True .Execute End With Do While .Find.Found .Case = wdTitleWord .Font.SmallCaps = True .Collapse wdCollapseEnd .Find.Execute Loop End With With ActiveDocument.Range With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "<[A-Z\-]{4;}>" .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchWildcards = True .Execute End With Do While .Find.Found .Case = wdTitleWord .Font.SmallCaps = True .Collapse wdCollapseEnd .Find.Execute Loop End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] Last edited by macropod; 02-25-2016 at 03:31 PM. Reason: Code Revision |
Tags |
allcaps, smallcaps, wildcards |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Include small caps in hierarchical multi-level list | Hardbottle | Word | 1 | 06-20-2015 05:12 AM |
change non capitalized text to capitalized text | antoniob | Excel | 8 | 10-13-2014 09:11 AM |
Is there a way to find CAPITALIZED words in a doc? | Bobosmite | Word | 8 | 01-28-2014 03:53 PM |
small caps auto check | gene | Word | 1 | 12-03-2011 03:04 PM |
French accents in small caps | nuitsdete | Word | 0 | 09-23-2011 01:53 AM |