Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-20-2012, 05:12 AM
tinfanide tinfanide is offline Select word by word Windows 7 64bit Select word by word Office 2010 32bit
Expert
Select word by word
 
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
  #2  
Old 01-21-2012, 06:45 AM
tinfanide tinfanide is offline Select word by word Windows 7 64bit Select word by word Office 2010 32bit
Expert
Select word by word
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

Self-solved.

Code:
Sub WordCount()

Dim n As Long
n = 0
For Each w In ActiveDocument.Words
    w.Select
    If UCase$(Left$(w, 1)) Like "[A-Z]" Then
    n = n + 1
    Debug.Print n
    End If
Next

End Sub
Codes similar to this.
Reply With Quote
  #3  
Old 01-26-2012, 01:45 PM
macropod's Avatar
macropod macropod is offline Select word by word Windows 7 64bit Select word by word Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,383
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi tinfanide,

Try a wildcard Find/Replace, where:
Find = <?@>
Replace = Text
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 01-27-2012, 12:37 AM
tinfanide tinfanide is offline Select word by word Windows 7 64bit Select word by word Office 2010 32bit
Expert
Select word by word
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

Yes, as expected. I've written up codes for such a simple task. Thanks for that.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Select word by word Select all textboxes in Word document msword270 Word 1 01-12-2012 11:41 AM
Unable to select anything in an MS Word Document PaulT Word 0 08-08-2011 07:45 PM
Select word by word Word XP - Can't select line RogerM Word 2 03-11-2011 01:26 PM
Force to select a group of word? jakekei Word 0 01-21-2010 04:20 PM
How to write in Word from Select query lakhan.p Word 0 03-27-2009 07:25 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:14 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft