Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-11-2013, 01:49 AM
kilburfi kilburfi is offline Loop action in Word until not found Windows 7 64bit Loop action in Word until not found Office 2007
Novice
Loop action in Word until not found
 
Join Date: Jul 2013
Posts: 2
kilburfi is on a distinguished road
Default Loop action in Word until not found

I have recorded a macro in Word which looks for a '?' and replaces that and everything after it (till the end of the line) with just a pargraph control (to move down to the next line). I have many occurences of ? and various text at the end of each line so have to run the macro as many times as the text exists. The text after the ? is not consistent so I can't just do a find and replace. My current code (from the Macro) which I want to loop is:

Selection.Find.ClearFormatting
With Selection.Find
.Text = "?"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.EndKey Unit:=wdLine, Extend:=wdExtend


Selection.Delete Unit:=wdCharacter, Count:=1

Selection.TypeParagraph
Reply With Quote
  #2  
Old 07-11-2013, 04:50 PM
gmaxey gmaxey is offline Loop action in Word until not found Windows 7 32bit Loop action in Word until not found Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Word.Range
 Set oRng = ActiveDocument.Range
 With oRng.Find
   .ClearFormatting
   .Text = "\?*^13"
   .Replacement.Text = ""
   .Forward = True
   .Wrap = wdFindContinue
   .Format = False
   .MatchCase = False
   .MatchWholeWord = False
   .MatchWildcards = True
   .MatchSoundsLike = False
   .MatchAllWordForms = False
   While .Execute
     oRng.MoveEnd wdCharacter, -1
     oRng.Delete
    Wend
 End With
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 07-12-2013, 01:26 AM
kilburfi kilburfi is offline Loop action in Word until not found Windows 7 64bit Loop action in Word until not found Office 2007
Novice
Loop action in Word until not found
 
Join Date: Jul 2013
Posts: 2
kilburfi is on a distinguished road
Default Worked a treat

Greg - thanks this code works a treat. I have to admit I was nearly there whilst waiting for a response but it took me a while (very VBA rusty)!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop action in Word until not found Macro to create new word doc and save the file using String found in the document VBNation Word VBA 2 02-08-2013 07:14 AM
Loop action in Word until not found Get para no where txt is found, and move text to end of paragraph using Word 201 marceepoo Word VBA 2 12-20-2012 11:42 AM
Loop action in Word until not found Macro to loop in Word Yamaha Rider Word VBA 2 02-07-2012 05:33 PM
How to link an action on one slide on a powerpoint with the same action on another slevinmj PowerPoint 0 02-24-2011 05:38 AM
templates 2003 can't be found in 2007 word tintincute Word 1 12-23-2009 08:55 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:45 AM.


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