PDA

View Full Version : Solved: Search for text in footer and delete row



fredlo2010
04-25-2012, 11:31 AM
Hi,

I need to search for a text string in a footer and then delete the table row that contains it.


Dim sText As String
Dim bmRange As Range

Application.ScreenUpdating = True

'DELETE ALL SUBTOTAL LINES

sText = "Subtotal"
Selection.Find.ClearFormatting
With Selection.Find
.Text = sText
.Wrap = wdFindContinue
End With
Do While Selection.Find.Execute
If Selection.Information(wdWithInTable) Then
Selection.Rows.Delete

End If
Loop



This works find for the document body but not the footer

Thanks

MacroShadow
04-25-2012, 12:05 PM
Try changing this line
If Selection.Information(wdWithInTable) Then
with this one
If Selection.Information(wdInHeaderFooter) > -1 Then

fredlo2010
04-25-2012, 01:31 PM
Thanks for the reply MacroShadow but it does not work. I need to extend my search to all the stories in the document but i cannot figure out how.

MacroShadow
04-25-2012, 02:02 PM
Take a look at http://word.mvps.org/FAQs/MacrosVBA/FindReplaceAllWithVBA.htm

fredlo2010
04-25-2012, 02:17 PM
Take a look at http://word.mvps.org/FAQs/MacrosVBA/FindReplaceAllWithVBA.htm


Thanks for the info. I have also read this but the issue is that I need to find the text string then expand the selection to the row and then delete the row if string is within a table.

:(

Frosty
04-25-2012, 02:44 PM
Fred,

Do you need to perform this search (and subsequent deletion of the row) on the document AND the headers/footers of that same document?

Or do you simply need to search in the headers/footers? There may be a better way to do this function, which is (conceptually):

For each table in my document's footers
Look for text
if text is found, delete the row
continue search until I'm done with the table
Next table