Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2005

Tip: Looking for answers? Try searching our database.

Trouble rearranging paragraphs

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nexan - 20 May 2005 20:31 GMT
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!
Jezebel - 20 May 2005 22:51 GMT
Search for: (^013)(ORG*^013)(NAME*^013)
Replace with: ^013\3\2

> I'm trying to set up a macro to sort groups of paragraphs that repeat as
> shown below:
[quoted text clipped - 56 lines]
>
> Thanks!
Nexan - 27 May 2005 17:30 GMT
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!

> Search for: (^013)(ORG*^013)(NAME*^013)
> Replace with: ^013\3\2
[quoted text clipped - 59 lines]
> >
> > Thanks!
Klaus Linke - 31 May 2005 19:33 GMT
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

> Thanks, Jezebel! Follow-up question, though: now I'm trying to move the DATE
> line to the top of the list below:
[quoted text clipped - 95 lines]
>> >
>> > Thanks!
Nexan - 07 Jun 2005 21:33 GMT
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!

> Hi Nexan,
>
[quoted text clipped - 107 lines]
> >> >
> >> > Thanks!
Helmut Weber - 08 Jun 2005 11:41 GMT
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/
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.