How to replace text and not have first letter of sentance capitalized?

K

kiln

Using code like the following, I want the replacement text to start with
"cc:" however word formats as "Cc:", how can I get around this?

With ActiveDocument.Content.Find
.MatchWholeWord = True
.Replacement.ClearFormatting
.Execute FindText:="CCPhysicians", ReplaceWith:=LCase("cc: ") _
& pstrCCPhysicians, Replace:=wdReplaceAll
End With

A secondary question is if pstrCCPhysicians is a zero length string, I
need to remove the placeholder text "CCPhysicians" in the doc as well as
it's line. I think word would regard the placeholder text
"CCPhysicians" as a paragraph, it's on it's own line...the IF part I
understand but how pull out that text/paragraph without leaving a blank
line.
 
H

Helmut Weber

hmm...

that's what my crystal ball is suggesting:

Sub Test700()
Dim rDcm As Range
Dim pstrCCPhysicians As String
pstrCCPhysicians = "cc: " 'or
' pstrCCPhysicians = "cc: "
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "CCPhysicians"
.MatchWholeWord = True
While .Execute
If pstrCCPhysicians <> "" Then
rDcm.Text = pstrCCPhysicians
Else
rDcm.Paragraphs(1).Range.Delete
End If
rDcm.Collapse Direction:=wdCollapseEnd
rDcm.End = ActiveDocument.Range.End
Wend
End With
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

kiln

Thanks Helmut that did it. What is the difference between what you did
and what I had originally tried? My replace operation invokes the 'first
letter of sentance cap' routine, and your setting the text does
not...but why?
 
H

Helmut Weber

Hi kiln,

Why? I don't know,

but changing a character to another in a range,
even, paradoxically, changing a character to more than
one character or changing it to "",
prevents autocorrect functions from executing.

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

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