Results 1 to 20 of 92

Thread: LinkToPrevious

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #9
    VBAX Regular
    Joined
    Nov 2011
    Posts
    71
    Location
    Quote Originally Posted by fumei View Post
    Why on earth are users making any comments on what is in a header!!!! That is absurd. It is not their document, tell them to mind their own business. Just kidding.

    Yes, I know the string with the tags are normal strings, it is annoying thing of having test random length starting and ending portions.
    Well, the good news is: whatever those tags are, and it doesn't matter why they are in headers, since they are only temporary! The algorithm is designed to find them and delete them... :-)
    Now, don't bother trying to figure out how to find each opening/closing tag, I've got that and it works. The only part that I am still struggling with is how to detect linked headers. I might give up if I see it's not worth it, but still, I'd like to know how to do it properly.
    My current code is failing:

    Dim oHF As HeaderFooter
            Dim oSection As Section
            Dim LinkToPreviousFlag As Integer
            For Each oSection In Application.ActiveDocument.Sections
                For Each oHF In oSection.Headers
                    LinkToPreviousFlag = 0
                    oHF.Range.Select
                    If oSection.PageSetup.OddAndEvenPagesHeaderFooter = False And oSection.PageSetup.DifferentFirstPageHeaderFooter = False And oSection.Headers(wdHeaderFooterPrimary).LinkToPrevious = True Then 'if FirstPage and OddEven are unchecked and header is linked
                        LinkToPreviousFlag = 1
                    ElseIf oSection.PageSetup.DifferentFirstPageHeaderFooter = True And oSection.Headers(wdHeaderFooterFirstPage).LinkToPrevious = True Then 'if FirstPage is checked and header is linked
                        LinkToPreviousFlag = 1
                    ElseIf oSection.PageSetup.OddAndEvenPagesHeaderFooter = True And oSection.Headers(wdHeaderFooterEvenPages).LinkToPrevious = True Then 'if OddEven is checked and header is linked
                        LinkToPreviousFlag = 1
                    End If
    those "if" don't give the right result... Any suggestion?

    Otherwise, I found another discussion on a similar issue (http://www.vbaexpress.com/forum/show...linktoprevious), and the suggestion is

    For Each S In ActiveDocument.Sections 
    If S.Index > 1 Then 
    For Each HF In S.Headers 
    If HF.Exists Then 
    MsgBox Choose(HF.Index, "Primary", "First Page", "Even Page") & " Header" & _ 
    " in Section " & S.Index & _ 
    " is " & IIf(HF.LinkToPrevious, "", "not ") & "linked to previous" 
    End If 
    Next 
    For Each HF In S.Footers 
    If HF.Exists Then 
    MsgBox Choose(HF.Index, "Primary", "First Page", "Even Page") & " Footer" & _ 
    " in Section " & S.Index & _ 
    " is " & IIf(HF.LinkToPrevious, "", "not ") & "linked to previous" 
    End If 
    Next 
    End If 
    Next S

    I will have to check this as well. Not sure how the msgbox works here though...
    Last edited by glencoe; 02-01-2014 at 11:17 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •