Thread: [Solved] Select word by word
View Single Post
 
Old 01-20-2012, 05:12 AM
tinfanide tinfanide is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default Select word by word

I wonder how I can replace every word in a document with some texts:

Document:

Apple
Cat

Replace every of them like:

Text
Text

Code:
Sub test()

For w = 1 To ActiveDocument.Words.Count
ActiveDocument.Words(w).Select
' fail to exclude the space following the selected word
If Not Selection.Text Like " *" Then
Selection.Text = "Text"
End If
Next w

End Sub
But this code just ends up like

Doc:
Text Text

It moves the second one up to the first paragraph
And I'm stuck at how to get rid of the space following the word
Reply With Quote