Question Locked

Code to delete graphics in a Word label

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I am using a 12 cell label for mailing labels. Each of the 6 standard cells for the label template was split and has a graphic with our address/logo in the top cell and the recipient address is placed in a field in the bottom cell. I want to write a code to delete the graphics from any cell where the field for the address in the cell below it is empty. I'm not sure it can be done. I would appreciate any suggestions.

3 replies

by kenneth.johnson9

If you are using a table in word, you can check the table using row and column much like referencing in Excel.

This example assumes that each address label is made up of a bunch of tables. If it is a single table then you just need to cycle through the rows and columns.

Let me know if this helps.
---------------------------------------------
Sub stuff()

'check to see if we have tables
If ActiveDocument.Tables.count >= 1 Then

'cycle through the number of tables one at a time
For var_tables = 1 To ActiveDocument.Tables.Count

'look at the second row(cell) in the table
'if blank then set the first row(cell) to nothing
If ActiveDocument.Tables(var_tables).Cell(2, 1).Range.Text = "" Then
ActiveDocument.Tables(1).Cell(1, 1).Range.Text = ""
End If
Next var_tables
End If
--------------------------------------------

End Sub

by thumbsup2

You said:

If ActiveDocument.Tables(var_tables).Cell(2, 1).Range.Text = "" Then
ActiveDocument.Tables(1).Cell(1, 1).Range.Text = ""
End If

Shouldn't that be:

If ActiveDocument.Tables(var_tables).Cell(2, 1).Range.Text = "" Then
ActiveDocument.Tables(var_tables).Cell(1, 1).Range.Text = ""
End If

If not, wouldn't it always be changing the first occurance of a table and not be following the pointer as it searches through the other tables?

This discussion is closed to new replies.