Mr. Daniels is correct. The process does not require the fourth step.
However, I do recommend a unique temporary string (e.g. "licnep" instead of
"pencil") something that is unlikely to appear elsewhere in the text. If
you want to use a macro approach the code is revised as follows:
Sub ScratchMacro()
Dim pFWIP As String
Dim pSWIP As String
Dim oRng As Word.Range
pFWIP = InputBox("Enter first word of pair.")
pSWIP = InputBox("Enter second word of pair.")
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = pFWIP
.Replacement.Text = "$$$$"
.Execute Replace:=wdReplaceAll
.Text = pSWIP
.Replacement.Text = pFWIP
.Execute Replace:=wdReplaceAll
.Text = "$$$$"
.Replacement.Text = pSWIP
.Execute Replace:=wdReplaceAll
End With
End Sub
You should keep in mind that this process can give some
unintended/unexpected results. Using "pen" and "book" as the word pair, in
basic form:
I have a book and a pen.
would be changed to:
I have a pen and a book.
Now if you have:
I have a pen and some books. You can have a book.
The result will depend on your MatchWholeWord setting. If set to "false"
true the result will be:
I have a book and some pens. You can have a pen.
If set to "true" the result will be:
I have a book and some books. You can have a pen.
You might say. I'll be sure to use "false" as my MatchWholeWord setting.
You should then consider:
I have some books, some pencils and a pen. You can have a book.
The result:
I have some pens, some bookcils and a book. You can have a pen.
My point is that it can get complicated so be sure to consider carefully
what you do and check the result.
anybody know the answer this question?
Words "book" and "pen" word has changed location, change the location
on these two by using a function in the program (Microsoft Word)
without losing any of the words. What is important is to understand
how to do this.
Hint:
You can use logic and function. (Function: replace all)
t.ex
Take a box a apple and a melon.
put apple and melon on the table.
If you replace the apple with a new melon.
And then replace the melons with apples.
So You've no melons left. This is what happens when you run the
function replace all.
Now you can with the help of box do anything crafty so we have both
apple and melon still make the switch locations. But thus need to do
things in more than two steps. (three steps)
--
Greg Maxey
See my web site
http://gregmaxey.mvps.org
for an eclectic collection of Word Tips.
"It is not the critic who counts, not the man who points out how the
strong man stumbles, or where the doer of deeds could have done them
better. The credit belongs to the man in the arena, whose face is
marred by dust and sweat and blood, who strives valiantly...who knows
the great enthusiasms, the great devotions, who spends himself in a
worthy cause, who at the best knows in the end the triumph of high
achievement, and who at the worst, if he fails, at least fails while
daring greatly, so that his place shall never be with those cold and
timid souls who have never known neither victory nor defeat." - TR