Hello folks,
Long time no talk! Hope you guys are all well.
Some time ago, I submitted a request about how to remove/delete some individual pages of a Word document. Now I have a macro setup to get the job faster and cleaner. However, as I succeed in deleting the last table, the header of the last table is retained and replace that of the 2nd last table that I have no intention to delete. So either I can modify the header of the table, or, it would probably harder, keep it from replacing the header of the table I want to keep. Here is the code:
Sub DeleteTableRange() 'run
For Each sect In ActiveDocument.Sections
contents = sect.Headers(1).Range.Tables(1)
If InStr(contents, "ECGs per each Filter combination") = 0 And _
InStr(contents, "per Finding") = 0 And _
InStr(contents, "per Overall Eval") = 0 And _
InStr(contents, "Visit and Timepoint") = 0 Then sect.Range.Delete
Next sect
With ActiveDocument
Set r = .GoTo(wdGoToPage, wdGoToLast)
Set r = .Range(r.Start - 1, .Characters.Count)
r.Delete
End With
On Error Resume Next
For h = 2 To 10
For i = 4 To 3 Step -1
ActiveDocument.Tables.Item(h).Columns(i).Delete
Next
Next
End Sub
The first part of the Sub is to remove the tables based on the headers of the table; the 2nd paragraph is to remove the last table; the last para is to delete a couple of columns of the tables.
Thanks in advance.
Long time no talk! Hope you guys are all well.
Some time ago, I submitted a request about how to remove/delete some individual pages of a Word document. Now I have a macro setup to get the job faster and cleaner. However, as I succeed in deleting the last table, the header of the last table is retained and replace that of the 2nd last table that I have no intention to delete. So either I can modify the header of the table, or, it would probably harder, keep it from replacing the header of the table I want to keep. Here is the code:
Sub DeleteTableRange() 'run
For Each sect In ActiveDocument.Sections
contents = sect.Headers(1).Range.Tables(1)
If InStr(contents, "ECGs per each Filter combination") = 0 And _
InStr(contents, "per Finding") = 0 And _
InStr(contents, "per Overall Eval") = 0 And _
InStr(contents, "Visit and Timepoint") = 0 Then sect.Range.Delete
Next sect
With ActiveDocument
Set r = .GoTo(wdGoToPage, wdGoToLast)
Set r = .Range(r.Start - 1, .Characters.Count)
r.Delete
End With
On Error Resume Next
For h = 2 To 10
For i = 4 To 3 Step -1
ActiveDocument.Tables.Item(h).Columns(i).Delete
Next
Next
End Sub
The first part of the Sub is to remove the tables based on the headers of the table; the 2nd paragraph is to remove the last table; the last para is to delete a couple of columns of the tables.
Thanks in advance.