PDA

View Full Version : [SOLVED:] Find text "xx", moveUp by two units and write "qqq" in the entire document



Cubajz
07-28-2017, 07:29 AM
Hi,
I am a begginer and was wondering if you could help me with this little word macro? I need to:

Find text: "xx"
after that press UP ARROW twice (Selection.MoveUp Unit:=wdLine, Count:=2)
and after that write: "qqq"

I need macro to search the entire document UNTIL it reaches the end of document (=when there is no more instance of "xx" to be found.

Can anyone help me with this? Sry if explanation is little bit messy, thanks for help in advance.:yes

gmaxey
07-28-2017, 11:40 AM
Try:


Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 7/28/2017
Dim oRng As Range
Dim oRngW As Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "xx"
While .Execute
Set oRngW = oRng.Duplicate
oRngW.Collapse wdCollapseStart
oRngW.Select
Selection.MoveUp wdLine, 2
Selection.Text = "qqq"
oRng.Collapse wdCollapseEnd
oRng.Select
Wend
End With
lbl_Exit:
Exit Sub
End Sub

Cubajz
07-31-2017, 01:19 AM
Works great, thank you very much.:clap: