Read text from table in a document, place it in a userform label,then delete the table

P

Patrickw

This refers to an earlier post entitled "Turning document text into a
label for my userform"

I have a letter in Word which is created from a merge. I want to be
able to add additional info from a userform. I would like the
userform to display information from the document in a label on the
userform; namely, one name (eg, "John Doe") or two names separated by
'and' (eg, "John Doe and Jane Doe")

I believe the easiest steps to accomplish this are as follows:
1. Create a special table in the document containing just the names of
the debtors when the document is created (from a merge)
2. Read the names from the table with a macro
3. Assign the names to a label on the userform
4. Delete the table from the document with the same macro.

This would certainly be easier than trying to parse the complex data
in another table. I already know how to read the data from such a
table (with help I received from an earlier thread) using the
following code:

' Read the client name(s) from a table in the document
strClientName = Left(ActiveDocument.Tables(1).Cell(1, 1). Range.Text,
_
Len(ActiveDocument.Tables(1).Cell(1, 1).Range.Text) - 2)
' The '-2' at the end strips two residual characters from the end
of _
the text as copied from the cell
' Convert strClientName to Title Case
strClientName = StrConv(strClientName, vbProperCase)
' If there are two clients, convert 'And' to lower case 'and'
If InStr(1, strClientName, "And", 0) > 0 Then
strClientName = Mid(strClientName, 1, InStr(1, strClientName, _
"And", 0) - 1) & LCase("And") & Mid(strClientName, InStr(1, _
strClientName, "And", 0) + Len("And"), 1000000)
End If

So how can I delete the same table from the document?
 
J

Jay Freedman

Since you already know (as shown in your code) that the table in
question is ActiveDocument.Tables(1), just add this line to the end of
your code:

ActiveDocument.Tables(1).Delete

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

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