Turning document text into a label for my userform

P

Patrickw

I have a table in my document which contains the following text
_______________________________________________________
|
|
| File No. «MAT_FileNumber»; «MAT_Client»; Chapter 13 |
| In re: John Doe and Jane Doe,
Debtors |
| Case No. 09-12345-RFN in the United States Bankruptcy Court |
| for the Northern District of Texas -- Fort Worth
Division |
|______________________________________________________ |

I'd like to find John Doe and Jane Doe (which will always appear
between
"In re: " and ", Debtors") or John Doe in between "In re:" and ",
Debtor"
and pass it to a string, strClientNames that I can use in a label (or
in
other controls, for that matter) on my userform.

I have looked at code which parses document text, but don't quite get
a good grip on use of InStr, Left, Mid and Len.
 
P

Patrickw

Question reformatted for clarity:

I have a table in my document which contains the following text
_______________________________________________________
|
| File No. 10123; Doe, John & Jane; Chapter 13
| In re: John Doe and Jane Doe, Debtors
| Case No. 09-12345-RFN in the United States Bankruptcy
| Court for the Northern District of Texas -- Fort Worth
|______________________________________________________

I'd like to find John Doe and Jane Doe (which will always appear
between "In re: " and ", Debtors") or John Doe in between "In re:" and
",
Debtor" and pass it to a string, strClientNames that I can use in a
label (or
in other controls, for that matter) on my userform.

I have looked at code which parses document text, but I don't quite
get
a the use of InStr, Left, Mid and Len.
 
G

Graham Mayor

Is the text to be found all in one cell? Which cell?
Is this the only table in the document?
The following may work - it rather depends on what exactly is in the cell
and whether there is a paragraph break immediately after 'Debtors'.


Dim strClientNames As String
With Selection
.HomeKey wdStory
.Find.Execute "In re:", _
MatchCase:=True, _
Forward:=True, _
Wrap:=wdFindStop
strClientNames = Selection.Range.Paragraphs(1).Range.Text
strClientNames = Mid(strClientNames, 8, _
Len(strClientNames) - 18)
'8 is the length of the start of the string to be omitted
'18 is the length of the start of the string to be omitted
'plus the length of the end of the string to be omitted
End With
MsgBox strClientNames

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
P

Patrickw

The text is all in one cell, and will vary slightly, as the data from
the initial merge varies. For instance, there may be one "Debtor" or
two "Debtors".

There are many tables in the document. This particular table is the
second table in the document. It contains one row and two colums.
The text appears in the second column.

The cell contains three paragraphs. There are paragraph marks after
"Chapter 13" in the first line and after "Debtors" (or "Debtor") in
the second line.
 
D

Doug Robbins - Word MVP

Something like:

Dim myrange As Range
Set myrange = ActiveDocument.Tables(2).Cell(1, 2).Range.Paragraphs(2).Range
myrange.Start = myrange.Start + InStr(myrange, ":") + 2
myrange.End = myrange.Start + InStr(myrange, "Debt") - 3
MsgBox myrange


--
Hope this helps

Doug Robbins - Word MVP
Please reply only to the newsgroups unless you wish to avail yourself of my
services on a paid, professional basis.
 

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