Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-06-2012, 11:31 AM
Yamaha Rider Yamaha Rider is offline Macro to loop in Word Windows XP Macro to loop in Word Office 2007
Novice
Macro to loop in Word
 
Join Date: Feb 2012
Posts: 2
Yamaha Rider is on a distinguished road
Default Macro to loop in Word

I have the word document that I want to color a particular wird a certain way. Attached is a sample with the Macro that I wrote. I now need to loop this macro throughout the document so does this throughtout hte document. Can somebody help me?

Here is what I have
Code:
Selection.Find.ClearFormatting
With Selection.Find
  .Text = "gopost`"
  .Replacement.Text = ""
  .Forward = True
  .Wrap = wdFindContinue
  .Format = False
  .MatchCase = False
  .MatchWholeWord = False
  .MatchWildcards = False
  .MatchSoundsLike = False
  .MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=2, Extend:=wdExtend
Selection.Font.color = wdColorRed
Selection.Font.Bold = wdToggle
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=4, Extend:=wdExtend
Selection.Font.color = 5296274
Selection.Font.Bold = wdToggle
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Font.color = wdColorRed
Selection.Font.Bold = wdToggle
Selection.MoveRight Unit:=wdCharacter, Count:=1
End Sub

Attached Files
File Type: docx The brown dog GOPOST.docx (10.0 KB, 12 views)

Last edited by macropod; 02-06-2012 at 03:28 PM. Reason: Added Code Tags
Reply With Quote
  #2  
Old 02-06-2012, 03:26 PM
macropod's Avatar
macropod macropod is offline Macro to loop in Word Windows 7 64bit Macro to loop in Word Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,344
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 Yamaha Rider,

Try:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Rng As Range
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Text = "gopost`"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute
  End With
  Do While .Find.Found
    .Font.Bold = True
    .Font.Color = wdColorRed
    Set Rng = .Duplicate
    Rng.Start = Rng.Start + 2
    Rng.End = Rng.End - 1
    Rng.Font.Color = 5296274
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-07-2012, 05:33 PM
Yamaha Rider Yamaha Rider is offline Macro to loop in Word Windows XP Macro to loop in Word Office 2007
Novice
Macro to loop in Word
 
Join Date: Feb 2012
Posts: 2
Yamaha Rider is on a distinguished road
Default

Awesome, Thank you
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use for loop in formula in VBA? tinfanide Excel Programming 1 12-06-2011 08:33 AM
Macro to loop in Word WORD Macro - import picture - resize - position - page break - loop Nano07 Word VBA 2 11-02-2011 05:14 AM
Macro to loop in Word Macro to loop in subfolders, change links, export xml data Catalin.B Excel Programming 2 09-08-2011 11:37 PM
Macro to loop in Word Continuous Loop cksm4 Word 6 01-06-2011 09:03 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:36 AM.


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