View Single Post
 
Old 06-05-2015, 12:47 PM
frustrated teacher frustrated teacher is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: May 2014
Posts: 12
frustrated teacher is on a distinguished road
Default Macro Needed to delete Unwanted paragraphs within a table.

I want to be able to delete the last paragraph within a table. After running several macros I am left with a table with just 3 paragraphs.

I have attached a sample BEFORE the macros are applied and a sample of what it looks like AFTER the macros are applied.

I tried the following code and it does not seem to work.

Code:
Sub UpdateTables()
Application.ScreenUpdating = False
Dim Tbl As Table, Rng1 As Range, Rng2 As Range
With ActiveDocument
  For Each Tbl In .Tables
    With Tbl
      If .NestingLevel = 1 Then
        Set Rng1 = .Cell(1, 1).Range
        With Rng1
          .End = .End - 1
          If (.Text Like "#.") Or (.Text Like "##.") Or (.Text Like "###.") Then
            Set Rng2 = .Rows(1).Cells(2).Range
            With Rng2
              .End = .End - 1
              While .Paragraphs.Last.Range.Tables(1).NestingLevel = 1
                .Paragraphs.Last.Range.Text = vbNullString
              Wend
            End With
          End If
        End With
      End If
    End With
  Next
End With
Set Rng1 = Nothing: Set Rng2 = Nothing
Application.ScreenUpdating = True
End Sub
Attached Files
File Type: docx sample files.docx (12.3 KB, 11 views)
File Type: docx sample files after macro.docx (12.0 KB, 13 views)
Reply With Quote