Sorted paragraphes

R

Ray

Hello
I need to sort an extract result in Word via VBA.

The extraction is made on the line : x = ExtractEBPs(h20)
in the code below
......
If SAHasObject(h20) <> 0 Then
Type_$ = GetProperty$("Type", h20)
If Type_$ = "Elementary Business Process" Then
x = ExtractEBPs(h20)
End If
End If
.....
I would like to know if it possible to sort the content of the variable x in
order to obtain sorted paragraphs
Thanks for your help

Ray
 
J

Jay Freedman

Hi, Ray,

I'll assume that the variable x is a String type and contains multiple
paragraphs separated by vbCr characters (paragraph marks).

The fastest and easiest way to sort the paragraphs is to create a temporary
Word document, insert the contents of x into it, use the temporary
document's .Range.Sort method, pull the sorted text out, and close the
temporary document without saving.

Here's a little demo:

Dim x As String
Dim tmpDoc As Document

x = "3. The quick brown fox" & vbCr & _
"2. The lazy dog" & vbCr & _
"1. The green chicken"

MsgBox "Before sort:" & vbCr & x

Set tmpDoc = Documents.Add
With tmpDoc.Range
.Text = x
.Sort
x = .Text
End With
tmpDoc.Close SaveChanges:=wdDoNotSaveChanges

MsgBox "After sort:" & vbCr & x
 
R

Ray

Thank you for your answer,
I am going to test your code and come back here to tell the result I obtain
Ray
 
R

Ray

I did not success in applicate your procécure on my macro. Some one else try
to do it. I will come here soon.
Ray
Thanks again
 

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