![]() |
|
|
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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
|
|
#3
|
|||
|
|||
|
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)!
|
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
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 |
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 |
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 |