Quantcast
Channel: Word for Developers forum
Viewing all articles
Browse latest Browse all 4350

How to achieve correct headers when showing hidden sections again in a document.

$
0
0

Dear colleagues in MSDN

I created a document intended to help sales people and customers to answer the right questions when dealing with different types of technical issues that they need help for. Since the technical issues require detailed information, it is a must to make it easy and motivating to fill in the data. Therefore the different types of technical issues are organized each in one section and when opening the questionnaire, all the sections besides of the first are hidden. As soon as the customer clicks on a checkbox for a specific technical question in the first section of the document, the corresponding section is shown and he is able to fill in the data. 

For that I use in the Checkbox_Change procedure following code:

ActiveDocument.Sections.Item("Number of corresponding section").Range.Select

If Checkbox.Value = True Then
        With Selection.Font
            .Hidden = False
        End With  

Else
        With Selection.Font
            .Hidden = True
        End With

End if

It works fine but I have following issue: Each section has its own header that is not connected to the section before but when the section appears, the first page has always the header of the section before. 

If I use the following code to change the text in the second cell of the table in the header of the corresponding section:

    Dim Kopf As HeaderFooter

        Set Kopf = ActiveDocument.Sections("Number of corresponding section").Headers(wdHeaderFooterPrimary)
        Kopf.Range.Tables.Item(1).Cell(1, 2).Range.Text = "Change text"

it changes the text in the header for the other pages of this section, but the first page remains with the header of the section before.

Even if I switch off all other sections besides of the first one, there is always after section 1 a blank page with the header of the next hidden section.

Since I believe that a lot of people would like questionaire sections in a Word document that only appear when they are needed I hope that someone of you could provide some help on this topic. 

Thank you very much

Andres



Viewing all articles
Browse latest Browse all 4350

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>