Range Start and End in Word 2003 Tables

A

Anne P.

I am working with Word 2003. I need to select information between two
bookmarks. The problem is this:

I have a two column table. In Row1, Column1 before any text is a bookmark
named CapBegin. The table could only be one row or it could be up to five
rows. If it is only one row, after the last text character in Row1, Column1
is a bookmark named CapEnd. If the table is two rows, the CapBegin bookmark
is at the beginning of the Row1, Column1 cell and the bookmark CapEnd is
after the last text character in Row2, Column1 cell.

I need to capture the text in between these two bookmarks (in column 1 only)
and enclose it in a new bookmark named CaseInfo without any table cell
markers. The reason for this is that I need to later capture the contents
of CaseInfo, copy it, create a new document based on an existing document
and paste it into an existing Table Cell as text, not as a nested table, but
I need to retain the formatting of the text that is being copied. Both
documents (source and destination have styles created with the same names,
but with slightly different formatting).

This is the code that I am currently using. However, using this code, the
text is pasted into the new document using the Normal style. I need the
text to be pasted using the styles that are applied in the original
document.

"Begin Code Block"
*****************************************************************************
Public Sub LitigationBack()
'get the info from the current document

Dim pCell As Word.Cell
Dim myTable As Table
Set myTable = ActiveDocument.Tables(1)
Set pCell = myTable.Cell(1, 1)
Do
If pCell.ColumnIndex = 1 Then
strCaseInfo = strCaseInfo & Left$(pCell.Range.Text,
Len(pCell.Range.Text) - 1) & vbCr
End If
Set pCell = pCell.Next
Loop Until pCell Is Nothing

RetrieveBookmarkInfo "Court", strCourt
RetrieveBookmarkInfo "District", strDistrict
RetrieveBookmarkInfo "IndexNo", strIndexNo
RetrieveBookmarkInfo "cmbAttyForSig", strAttyFor
RetrieveBookmarkInfo "Title", strTitle
RetrieveBookmarkInfo "txtAddress", strAddress

'create the litback and past info
Documents.Add Template:= _
Application.Options.DefaultFilePath(wdWorkgroupTemplatesPath) _
& "\SK Pleadings\Pleading LitBack.doc", NewTemplate:=False,
DocumentType:=0

UpdateBookmark "Court", strCourt
UpdateBookmark "District", strDistrict
UpdateBookmark "Index", strIndexNo
UpdateBookmark "CaseInfo", strCaseInfo
UpdateBookmark "AttyFor", strAttyFor
UpdateBookmark "Title", strTitle
UpdateBookmark "Address", strAddress

End Sub
"End Code Block"
*****************************************************************************

Any thoughts would be greatly appreciated.

Thanks,
Anne
 
J

Jezebel

If you need to retain formatting information, then copying the Text won't
work. You need to copy the ranges themselves.

Don't understand what all the stuff about bookmarks is getting at. From your
description, you're simply copy the contents of column 1, from however many
rows there are in the table.

Try something along these lines ---

Set pTarget = Doc2.Bookmarks("CaseInfo").Range
Set pCell = MyTable.Cell(1, 1)
Do
If pCell .ColumnIndex = 1 Then
Doc1.Range(pCell .Range.Start, pCell .Range.End - 1).Copy
pTarget .Paste
pTarget .InsertParagraphAfter
pTarget .Collapse Direction:=wdCollapseEnd
End If
Set pCell = pCell .Next
Loop Until pCell Is Nothing

You'll need more to it than this --- eg to deal with the initial bookmark
contents, and to redefine the bookmark on completion.
 
A

Anne P.

Jezebel,

I incorporated the code you gave into my code in the following manner:

Public Sub LitigationBack()
'get the info from the current document
Dim pCell As Word.Cell
Dim myTable As Table
Dim pTarget As Range
Dim doc1 As Word.Document
Dim doc2 As Word.Document


Set doc1 = ActiveDocument

RetrieveBookmarkInfo "Court", strCourt
RetrieveBookmarkInfo "District", strDistrict
RetrieveBookmarkInfo "IndexNo", strIndexNo
RetrieveBookmarkInfo "cmbAttyForSig", strAttyFor
RetrieveBookmarkInfo "Title", strTitle
RetrieveBookmarkInfo "txtAddress", strAddress


'create the litback and paste info except for case info
Documents.Add Template:= _
Application.Options.DefaultFilePath(wdWorkgroupTemplatesPath) _
& "\SK Pleadings\Pleading LitBack.doc", NewTemplate:=False,
DocumentType:=0

UpdateBookmark "Court", strCourt
UpdateBookmark "District", strDistrict
UpdateBookmark "Index", strIndexNo
UpdateBookmark "AttyFor", strAttyFor
UpdateBookmark "Title", strTitle
UpdateBookmark "Address", strAddress

Set doc2 = ActiveDocument


Set myTable = doc1.Tables(1)
Set pTarget = doc2.Bookmarks("CaseInfo").Range
Set pCell = myTable.Cell(1, 1)
Do
If pCell.ColumnIndex = 1 Then
doc1.Range(pCell.Range.Start, pCell.Range.End - 1).Copy
pTarget.Paste
pTarget.InsertParagraphAfter
pTarget.Collapse Direction:=wdCollapseEnd
End If
Set pCell = pCell.Next
Loop Until pCell Is Nothing

End Sub

It works great except for one thing. The last line of each of the table
cells is not retaining the formatting when it is pasted into the new
document. If I edit the document and place a carriage return before the End
of Cell marker (so that there is a new blank line after the end of the last
piece of text), it works beautifully.

Any ideas on why the last line is not retaining the formatting?

Thanks,
Anne P.
 
D

doug danciger

This is not a programming question but a general one. The subject panel
would only accept my request in the Word Programming category. Here's my
question:

How do you set up word completion; suggested words which appear in the
window above the input panel? This is easy to find on my 2003 Windows
powered Samsung i700 phone, but it isn't so on my notebook which runs Windows
XP. Please respond at your convenience.
--
I hope this was clear.

Sincerely,

Doug Danciger
(901) 573-6229
 

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