Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to modify header contents of a table in 2010 MS Word?

Status
Not open for further replies.

feipezi

IS-IT--Management
Aug 10, 2006
316
0
0
US
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.
 
Please use the appropriate forum for your questions.
Since this is a Word VBA question, you should post it in the forum707

And please use TGML tags to format your code.
It is a LOT easier to read, see: :)

Code:
...
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

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
Without seeing a sample document, I'm not entirely sure what your code is trying to do, or doing, but it seems likely that the problem is what happens when you delete a section or, more specifically, a section break.

The links between headers across sections are complex and deleting sections forces Word to make decisions about which headers to keep, and it doesn't always (or even normally) make the decision you would make.

Although the underlying issue is broader, this question, as Andy says, really belongs in the VBA forum, If you could post more details there, I could take a look at it.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top