Question

Locked

Code to delete graphics in a Word label

By dtenbrink ·
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.

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

maybe try this...

by kenneth.johnson9 In reply to Code to delete graphics i ...

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

Collapse -

Pardon me, but..............

by ThumbsUp2 In reply to maybe try this...

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?

Back to Hardware Forum
2 total posts (Page 1 of 1)  

Related Forums