INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

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

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

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

(OP)
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.

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

Please use the appropriate forum for your questions.
Since this is a Word VBA question, you should post it in the forum707: VBA Visual Basic for Applications (Microsoft)

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

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.

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

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close