Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2007

Tip: Looking for answers? Try searching our database.

Can't Delete Space After Period

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
George Lee - 16 Nov 2007 19:05 GMT
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
Helmut Weber - 17 Nov 2007 12:01 GMT
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
George Lee - 20 Nov 2007 14:48 GMT
Good call setting the range.text to nothing. It works.

> Hi George,
>
[quoted text clipped - 22 lines]
>
> Vista Small Business, Office XP
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.