×
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.

Students Click Here

How to update the TOC header number when I hide some section in word document use VBA

How to update the TOC header number when I hide some section in word document use VBA

How to update the TOC header number when I hide some section in word document use VBA

(OP)
Hi, All:
Nice to meet you all here, I have a question about the Word VBA program. How I can update my table of content, when I hide one section? I use one click code like this:
Private Sub CheckBox1_Click()
Dim Doc As Document
Set Doc = ActiveDocument
If CheckBox1.Value Then
Doc.Sections(7).Range.Font.Hidden = True
Else
Doc.Sections(7).Range.Font.Hidden = Fault
End If

Application.ScreenRefresh
End Sub
*********************************************
It can hide the section, but after I update the TOC, the format as below:
5. 33
5.1 33
5.2 33
5.3 33
5.4 33
5.5 33
5.5.1 33
5.5.2 33
5.5.3 33
6. SHREDDER SYSTEM OPERATION 33
6.1 TOPPER SHREDDER (SHREDDER 1) 33
6.1.1 JOG MODE 36
6.2 BOTTOM SHREDDER 37
6.2.1 JOG MODE 37
6.3 DIVERTER 38
6.3.1 CONTROL OPERATORS 38
6.3.2 JOG MODE 38
*****************************************
Above I use the code like this:
Sub FieldsUpdates()
Dim oStory As Range
For Each oStory In ActiveDocument.StoryRanges
oStory.Fields.Update
If oStory.StoryType <> wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
oStory.Fields.Update
Wend
End If
Next oStory
Set oStory = Nothing

Dim TOC As TableOfContents
For Each TOC In ActiveDocument.TablesOfContents
TOC.Update
Next
End Sub
********************************************************
The section already hide in the document, but my hide section TOC should also hide and header section 6 should change number to header 5, how I can do it please?
I am not a professional programmer, I am Electrical Engineer. Thanks for your help, I appreciate your time for me.

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! Already a Member? Login

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