Solved

Run macro on tables where specific cells are blank.

Posted on 2015-01-30
2
74 Views
Last Modified: 2016-02-10
Dear Experts,

can somebody help me re-write this code so that ...
... only tables get worked on where the 2nd and 3nd cell in the first row are blank, i.e. Cell(Row:=1;Column:=2) and Cell(Row:=1;Column:=3) are blank.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas

Sub Format_First_Row_All_Tables

Dim tbl as table

For Each tbl In ActiveDocument.Tables
        With tbl.rows.First
            .Range.Font.Name = "Verdana"
            .Range.Font.Size = 7.5
            .Range.Font.Bold = True
            .Shading.BackgroundPatternColor = wdColorGray25
            .HeadingFormat = True
            .HeightRule = wdRowHeightAtLeast
            .Height = CentimetersToPoints(0.9)
        End With
 Next tbl

End Sub

Open in new window

0
Comment
Question by:AndreasHermle
2 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 40580912
I think the easiest way is to check the length of the cell ranges. The length of the range of an empty cell is 2.
Sub Format_First_Row_All_Tables()

Dim tbl As Table

For Each tbl In ActiveDocument.Tables
    If Len(tbl.Cell(1, 2).Range) + Len(tbl.Cell(1, 3).Range) = 4 Then
        With tbl.Rows.First
            .Range.Font.Name = "Verdana"
            .Range.Font.Size = 7.5
            .Range.Font.Bold = True
            .Shading.BackgroundPatternColor = wdColorGray25
            .HeadingFormat = True
            .HeightRule = wdRowHeightAtLeast
            .Height = CentimetersToPoints(0.9)
        End With
    End If
 Next tbl

Open in new window

0
 

Author Closing Comment

by:AndreasHermle
ID: 40583459
Hi Graham,

great, this did the trick. Thank you very much for your professional and swift support.

Regards, Andreas
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

It is often necessary in this forum and others to illustrate Word fields as text with the field delimiters replaced with the curly brackets that the delimiters resemble when field codes are being displayed on the document. This means that the text c…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now