Can't Delete Space After Period

G

George Lee

I can't delete a space (ASCII 32) in Word 2003 after a period, any
punctuation mark, and in some instances, for no apparent reason. Why not, and
more importantly, how can they be deleted? The code is the condensed version
and intentionally uses wildcards (there's additional processing that has been
removed) but it still exposes the problem.

Public Sub Macro6()
On Error GoTo MyErrorHandler

Dim whichDocument As Document
Set whichDocument = ActiveDocument

Dim findrange As Range
Set findrange = whichDocument.Range
findrange.Find.ClearFormatting
findrange.Find.MatchWildcards = True
findrange.Find.Text = "*"

While findrange.Find.Execute() = True
findrange.Delete
DoEvents
Wend

Exit Sub

MyErrorHandler:
MsgBox "Macro6" & vbCrLf & vbCrLf & "Err = " & Err.Number & vbCrLf &
"Description: " & Err.Description
End Sub
 
H

Helmut Weber

Hi George,

there may be autocorrect options,
or something the like,
which do not prevent replacing,
but correct your replacing immediately.

So I'd try at first,
not to delete or to replace anything,
but set the text of the found range to a new value,
like that (pseudocode):

While .Execute()
range.text = ""
'probably collapse the range here
Wend


HTH


--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 

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