How to keep replacement in lowercase

D

dvdastor

Hi all,

I am having an issue with keeping my replacement formatting text in
lowercase if the text it comes across is uppercase.
I am searching through the document looking for 12 pt, Arial font and
apply HTML formatting tags. All this works just fine, but my issue is
with uppercase words.

Here is an example:

This is some text becomes

<font size="12" face="Arial">This is some text</font>

however,

THIS IS SOME TEXT becomes

<FONT SIZE="12" FACE="ARIAL">THIS IS SOME TEXT</FONT>

Is there a way to keep the <font size...> text in alll lowercase even
though the range is uppercase? I tried using matchcase, but that
didn't seem to help.

Thanks!!!
 
H

Helmut Weber

Hi,

without covering all possible variations,
as, e.g., if a text is in real caps, Word tells me,
it would be formatted as "All caps", though it isn't,

like this, if the original text was formatted as "All caps"

Sub test7568()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
ResetSearch
With rDcm.Find
.Text = "Text"
.Replacement.Text = "Text"
.Replacement.Font.AllCaps = False
.Execute Replace:=wdReplaceAll
End With
ResetSearch
End Sub

And like this, if the original text is in real caps.

Sub test7569()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
ResetSearch
With rDcm.Find
.Text = "TEXT"
.Replacement.Text = "Text"
.MatchCase = True
.Execute Replace:=wdReplaceAll
End With
ResetSearch
End Sub
' ---
Public Sub ResetSearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
' plus some more if needed
.Execute
End With
End Sub


Greetings from Bavaria, Germany

Helmut Weber, MVP, WordVBA

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

Klaus Linke

I tried using matchcase, but that didn't seem to help.


Hi dvdastor,

Try again?

".MatchCase=True" should do the trick!

Klaus
 

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