Thread: [Solved] Word VBA Capabilities
View Single Post
 
Old 05-18-2019, 03:40 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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

Depending on the complexity of your document vis-à-vis the page layouts (e.g. orientations, margins, page columns, headers & footers), the code might be as simple as:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Tbl As Table, r As Long, bDel As Boolean
bDel = False
With ActiveDocument
  Set Tbl = .Sections(4).Range.Tables(1)
    For r = Tbl.Rows.Count To 1 Step -1
      If Split(Tbl.Cell(r, 3).Range.Text, vbCr)(0) = "Delete" Then
        If r = 4 Then bDel = True Else .Sections(r).Range.Delete
      End If
    Next
    If bDel = True Then Tbl.Range.Sections(1).Range.Delete
End With
Application.ScreenUpdating = True
End Sub
The above code looks at the first table in Section 4, using the presence of 'Delete' in column 3 of a given row to delete the corresponding Section.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote