Solved

Run macro on tables where specific cells are blank.

Posted on 2015-01-30
2
77 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

911 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

15 Experts available now in Live!

Get 1:1 Help Now