How execute this macro to the end of a document?

N

Nomey

Dear VBA-ists,

How can I have the following macro execute until the end of the active document is reached? Th epurpose is to convert all instances of words (and phrases) in all caps to underscore, and then to small caps.

Best regards,
Shirley Nomey


Sub ChangeCapsToSmallCaps()
Selection.Find.ClearFormatting
With Selection.Find
.Text = "([A-Z]{2;})"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.Range.Case = wdLowerCase
With Selection.Font
.SmallCaps = True
End With
End Sub
 
H

Helmut Weber

Hi Nomey,

this is not modifying your macro,
it is just the way I would do it,
and there are many other ways.


Sub Macro12()
Dim rTmp As Range
Set rTmp = ActiveDocument.Range
With rTmp.Find
.Text = "([A-Z]{2;})"
.MatchWildcards = True
While .Execute
rTmp.Case = wdLowerCase
rTmp.Font.Underline = wdUnderlineSingle
rTmp.Font.SmallCaps = True
rTmp.Start = rTmp.End
rTmp.End = ActiveDocument.Range.End
Wend
End With
End Sub


Note that .Text = "([A-Z]{2;})"
contains the listseparator ";" (semicolon) for
germany, netherlands and northern european countries.
(seems that nobody knows exactly for which),
whereas the listseparator is "," comma fpr the rest
of the world.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
N

Nomey

Hi Helmut,

Thanks for your help. Your macro is of course a million times more efficient; mine was recorded first and edited later. And yes, we use a Dutch version with semicolons as list separators (which we could change in the Windows Locale settings, if we wanted to).

Best regards,
Shirley
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top