Locate images and text in tables

P

Paul Martin

Hi guys

I'm familiar with VBA but not with the Word object model. I would
like to loop through each table in a document and, if the first row
contains an image, delete the subsequent rows. If a row has the word
"dates" in the first cell of a row, I want to cut the table, paste as
text, with a linebreak to replace each cell, and delete the word
"dates".

Any advice appreciated. Thanks in advance.

Paul Martin
Melbourne, Australia
 
H

Helmut Weber

Hi Paul,
Any advice appreciated.

well, something along these lines, perhaps:

Sub Test4a6()
Dim oTbl As Table
Dim oCll As Cell
Dim x As Long
On Error Resume Next
For Each oTbl In ActiveDocument.Tables
If oTbl.Rows(1).Range.InlineShapes.Count > 0 Or _
oTbl.Rows(1).Range.ShapeRange.Count > 0 Then
For x = oTbl.Rows.Count To 2 Step -1
oTbl.Rows(x).Delete
Next
End If
Next
For Each oTbl In ActiveDocument.Tables
oTbl.Range.Columns(1).Select
For Each oCll In Selection.Cells
If InStr(oCll.Range.Text, "dates") > 0 Then
oCll.Range.Text = ""
oTbl.ConvertToText Separator:=wdSeparateByParagraphs
End If
Next
Next
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
P

Paul Martin

Danke Helmut

Paul


Hi Paul,


well, something along these lines, perhaps:

Sub Test4a6()
Dim oTbl As Table
Dim oCll As Cell
Dim x As Long
On Error Resume Next
For Each oTbl In ActiveDocument.Tables
   If oTbl.Rows(1).Range.InlineShapes.Count > 0 Or _
   oTbl.Rows(1).Range.ShapeRange.Count > 0 Then
      For x = oTbl.Rows.Count To 2 Step -1
         oTbl.Rows(x).Delete
      Next
   End If
Next
For Each oTbl In ActiveDocument.Tables
   oTbl.Range.Columns(1).Select
   For Each oCll In Selection.Cells
   If InStr(oCll.Range.Text, "dates") > 0 Then
      oCll.Range.Text = ""
      oTbl.ConvertToText Separator:=wdSeparateByParagraphs
   End If
   Next
Next
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top