none
Find same as previous disabled headers and footers RRS feed

  • Question

  • Hi,

    I've to create a macro to find 'same as previous' disabled pages and then add MS Word comment to each pages.

    Is it possible to do that in Word?

    Any inputs would be much appreciated.


    .


    • Edited by Sam1085 Thursday, August 11, 2016 1:37 PM updated
    Thursday, August 11, 2016 1:36 PM

Answers

  • Hi,

    Try to use For Loop instead of foreach

    For i = 2 To ActiveDocument.Sections.Count
    Set oSec = ActiveDocument.Sections(i)
     If oSec.Headers(wdHeaderFooterPrimary).LinkToPrevious = False Then
           Set oRng = oSec.Range
           oRng.Collapse
           ActiveDocument.Comments.Add oRng, "Link to previous disabled"
        End If
    Next i



    Friday, August 12, 2016 3:02 PM
    Moderator

All replies

  • >>I've to create a macro to find 'same as previous' disabled pages and then add MS Word comment to each pages.

    What do you mean "disabled pages"?

    To find pages whether their HeaderFooter are same as previous, you could use HeaderFooter.LinkToPrevious Property (Word)

    To add comment, you could use Comments.Add Method (Word). However, we are unable to add comment to the headers or footers.

    Friday, August 12, 2016 5:57 AM
    Moderator
  • Hi Celeste,

    Thanks for the response.

    I meant 'Link to previous' deactivated pages.

    Simply I've to find all link to previous deactivated pages and then add a comment to the each top of pages. Because as you mentioned above, we are unable to add comments to the header footer fields.

    I've tried the following code to this. But some thing went wrong in my code.

    Private Sub Demo()
    Application.ScreenUpdating = False
    Dim oSec As Section
    Dim oRng As Range
    For Each oSec In ActiveDocument.Selection.HeaderFooter
        If oSec.LinkToPrevious = False Then
           Set oRng = oSec.Range
           oRng.Collapse
           ActiveDocument.Comments.Add oRng, "Link to previous disabled"
        End If
    Next oSec
    Application.ScreenUpdating = True
    End Sub
    

    Thanks!


    .

    Friday, August 12, 2016 10:05 AM
  • Hi,

    Try the code below.

    Private Sub Demo()
    Application.ScreenUpdating = False
    Dim oSec As Section
    Dim oRng As Range
    For Each oSec In ActiveDocument.Sections
        If oSec.Headers(wdHeaderFooterPrimary).LinkToPrevious = False Then
           Set oRng = oSec.Range
           oRng.Collapse
           ActiveDocument.Comments.Add oRng, "Link to previous disabled"
        End If
    Next oSec
    Application.ScreenUpdating = True
    End Sub
    
    

    Friday, August 12, 2016 11:10 AM
    Moderator
  • Thanks Celeste,

    I tried the above code. But it will add comment to the first page. (1st page haven't previous page link)

    But I've to check link to previous un-checked pages.


    .

    Friday, August 12, 2016 2:04 PM
  • Hi,

    Try to use For Loop instead of foreach

    For i = 2 To ActiveDocument.Sections.Count
    Set oSec = ActiveDocument.Sections(i)
     If oSec.Headers(wdHeaderFooterPrimary).LinkToPrevious = False Then
           Set oRng = oSec.Range
           oRng.Collapse
           ActiveDocument.Comments.Add oRng, "Link to previous disabled"
        End If
    Next i



    Friday, August 12, 2016 3:02 PM
    Moderator
  • Thanks Celeste,

    It's works for me.. I've customized the above code as per my requirements. Thanks!


    .

    Friday, August 12, 2016 3:21 PM