Thread: [Solved] Word VBA: Continuous Find???
View Single Post
 
Old 04-22-2012, 03:50 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi tinfanide,

It's not entirely clear what you're after. If you're trying to delete the empty paragraph following "ordered by ministers.", you could use a macro like the following.

This macro deletes all tabs, leading & trailing spaces, linefeeds and empty paragraphs (including those with spaces only) from all cells in all tables (including nested tables) in the active document, without otherwise affecting the formatting of text in the cells.
Code:
Sub TableCleaner()
Application.ScreenUpdating = False
Dim Tbl As Table, Cel As Cell, Rng As Range, Para As Paragraph
With ActiveDocument
  For Each Tbl In .Tables
    With Tbl.Range.Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Forward = True
      .Wrap = wdFindStop
      .Format = False
      .MatchCase = False
      .MatchWholeWord = False
      .MatchWildcards = True
      .MatchSoundsLike = False
      .MatchAllWordForms = False
      .Text = "[^t]"
      .Replacement.Text = " "
      .Execute Replace:=wdReplaceAll
      .Text = "[ ]{2,}"
      .Replacement.Text = " "
      .Execute Replace:=wdReplaceAll
      .Text = "[^l^13]{1,}"
      .Replacement.Text = "^p"
      .Execute Replace:=wdReplaceAll
      .Text = "[^13 ]{2,}"
      .Replacement.Text = "^p"
      .Execute Replace:=wdReplaceAll
    End With
    For Each Cel In Tbl.Range.Cells
      Set Rng = Cel.Range
      Rng.End = Rng.End - 1
      If Rng.Start <> Rng.End Then
        For Each Para In Rng.Paragraphs
          With Para.Range
            If .Characters.Count = 1 And .Cells.Count = 1 Then
              .Characters.First = vbNullString
              On Error Resume Next
              If .End = .Cells(1).Range.End Then .Characters.Last.Previous.Delete
            End If
            If .End = Rng.End Then Rng.Characters.Last = vbNullString
          End With
        Next
      End If
    Next
  Next
End With
Set Rng = Nothing
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote