Trouble rearranging paragraphs

N

Nexan

I'm trying to set up a macro to sort groups of paragraphs that repeat as
shown below:

DATE: XXXXXXX
PHONE: XXXXXXX
CALL CENTER: XXXXXXX
ACCOUNT: XXXXXXX
ORG NAME: XXXXXXX
REASON TO CALL FROM SAMPLE: XXXXXXX
REASON TO CALL FROM CUSTOMER: XXXXXXX
CONTACT NUMBER: XXXXXXX
TIME TO CALL: XXXXXXX
COMPANY PHONE: XXXXXXX
NAME: Jane Doe
ISSUE IN DETAIL: XXXXXXX
SPECIAL: XXXXXXX

DATE: XXXXXXX
PHONE: XXXXXXX
CALL CENTER: XXXXXXX
ACCOUNT: XXXXXXX
ORG NAME: XXXXXXX
REASON TO CALL FROM SAMPLE: XXXXXXX
REASON TO CALL FROM CUSTOMER: XXXXXXX
CONTACT NUMBER: XXXXXXX
TIME TO CALL: XXXXXXX
COMPANY PHONE: XXXXXXX
NAME: Joe Blow
ISSUE IN DETAIL: XXXXXXX
SPECIAL: XXXXXXX

I'm trying to use the following formula:

Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "(ORG NAME:*^13REASON TO CALL FROM SAMPLE:*^13REASON TO CALL
FROM CUSTOMER:*^13CONTACT NUMBER:^13TIME TO CALL:*^13COMPANY
PHONE:*^13)(NAME:*^13)"
.Replacement.Text = "\2\1"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

All I'm trying to do is move "NAME:" up before "ORG NAME:". However, when I
use this formula, it moves both the first -and- the last instance of "NAME:"
in the document above the first instance of "ORG NAME:". Is there any way to
avoid this?

Thanks!
 
N

Nexan

Thanks, Jezebel! Follow-up question, though: now I'm trying to move the DATE
line to the top of the list below:

SAMPLE NAME: XXXXXXXXXX
ADDRESS: XXXXXXXXXX
CITY: XXXXXXXXXX
STATE: XXXXXXXXXX
PHONE: XXXXXXXXXX
CONTACT PHONE: XXXXXXXXXX
TIME TO CALL: XXXXXXXXXX
REASON: XXXXXXXXXX
Q20: XXXXXXXXXX
ACCOUNT: XXXXXXXXXX
REGION: XXXXXXXXXX
SERVICE CENTER: XXXXXXXXXX
SERVICE DATE: XXXXXXXXXX
DATE: XXXXXXXXXX

I'm trying to use this, but it's not working:

With Selection.Find
.Text = "(^013)(SAMPLE*^013)(DATE*^013)"
.Replacement.Text = "^013\3\2"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

Can you tell what I'm doing wrong? Thanks!
 
K

Klaus Linke

Hi Nexan,

Should work fine... if there's a paragraph mark above the "SAMPLE NAME:" line.
You might also want to go to the start of the document first... else the search might miss the "record" you're in:
Selection.HomeKey Unit:=wdStory

BTW, use ^p or \1 instead of ^013 in the replacement text.
^013 will insert a character that looks like a paragraph mark, but doesn't act like one (... doesn't store the paragraph formatting such as the style).

Greetings,
Klaus
 
N

Nexan

Klaus,

Okay, I've switched to this:

With Selection.Find
.Text = "(^013)(SAMPLE*^013)(DATE*^013)"
.Replacement.Text = "^p\3\2"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

Still no luck. Can you think of any other factors that might be at work here?

Thanks!
 
H

Helmut Weber

Hi everybody,

May I propose something completely different?
If the document has a persistent structure,
that is blocks of 14 paragraphs, which means,
that it's end is an empty paragraph, too,
then...

Sub SwitchParagraphs()
' example for paragraphs 5 and 11
' in a doc a blocks of 14 paragraphs
Dim l As Long
With ActiveDocument.Paragraphs
For l = 1 To .Count Step 14
.Item(l + 4).Range.InsertBefore .Item(l + 10).Range.Text
.Item(l + 11).Range.Delete
Next
End With
End Sub

Sometimes wildcard search is tempting.
But hard to read and to understand for me sometimes, too.

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top