Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format MS Word cell borders based on presence of merge data

Status
Not open for further replies.

Brenlini

Technical User
May 16, 2009
2
US
I have a project where page 2 of a mail merge document contains a single table. The number of rows to be printed is variable between 1-9 - all cells contain borders. If the data field placed in the left-most cell in the row is null, then the entire row is "not to be printed". Which can be accomplished by removing the left/right/bottom borders of that cell.

The only similar post that I found here is thread707-1090662

I've attempted to do this in Access as this could be easily done. Unfortunately, page 1 of the document is landscape and page 2 is portrait. I've been attempting to control this in access VB, but not having any luck there.

Any help would be great.

Thanks,
ERNIE

 
Hi Ernie,

From what you've described, I suspect you're trying to merge multiple records into the same letter. You should be able to do that with a Catalogue/Directory Mailmerge (the terminolgy depends on the Word version). To see how, check out my Word 97-2007 Catalogue/Directory Mailmerge Tutorial at:
or
Do read the tutorial before trying to use the mailmerge document included with it.

Incorporating a landscape page into the merge doesn't require any major changes - just the insertion of the required Section breaks into the field coding before & after the repeated data.

Cheers


[MS MVP - Word]
 
I believe that I have the merged data aspect and the portrait/landscape covered when using MS WORD. To describe: each table row contains 4 columns. There are a max of 9 rows. The data file being attached is a dbf III format that contains all data fields (9 rows X 4 columns = 36 data fields), so each data field will be placed in the corresponding table cell.

The issue with WORD though is that the goal is to only "print" the table rows where data is populated. So if data exists for only 3 of the nine rows, then the cell borders for rows 4-9 need to be removed so that they are not "printed". So I need to be able to programmatically control the table cell borders based on the merged data file.

Thanks,
ERNIE
 
Hi Ernie,

My tutorial shows how to accomplish essentially the same thing, but approaches the problem from a different direction; it only creates the table rows for which the required data are present.

From what you've described so far, it seems you really don't need to rows lacking data in column A to exist at all. In that case, you may as well simply delete them from the merged output via a macro like:
Code:
Sub CleanTables()
Dim oTbl As Table
Dim i As Integer
Application.ScreenUpdating = False
With ActiveDocument
  For Each oTbl In .Tables
    For i = oTbl.Rows.Count To 1 Step -1
      If Len(oTbl.Cell(i, 1).Range.Text) = 2 Then oTbl.Rows(i).Delete
    Next
  Next
End With
Application.ScreenUpdating = True
End Sub
Cheers

[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top