Friday, March 14, 2014

How to detect footnote and endnote whether they exist in word document

Leave a Comment


In this article, it is a bit strange that why we need to check whether the footnote or endnote exists or not with word document. The reason is that word document separates the document into these views, main document view and footnote or endnote view. When you run your macro code, it work only in the main view, so in the footnote or endnote views it doesn't work.

How to make macro work in footnote or endnote view
We need to detect the footnote or endnote and switch from main view to footnote or endnote view with ActiveWindow.ActivePane.View.Type.


Detect Endnote
FunctionEndnotesExist() As Boolean
    DimmyStoryRange As Range
    ForEach myStoryRange In ActiveDocument.StoryRanges
        IfmyStoryRange.StoryType = wdEndnotesStory Then
            EndnotesExist = True
            ExitFor
        End If
    Next myStoryRange
EndFunction


Detect Footnote
FunctionFootnotesExist() As Boolean
    DimmyStoryRange As Range
    ForEach myStoryRange In ActiveDocument.StoryRanges
        IfmyStoryRange.StoryType = wdFootnotesStory Then
            FootnotesExist = True
            ExitFor
        End If
    Next myStoryRange
EndFunction

Conclusion, detect footnote or endnote when using vba programming with word document is important because when you using vba code to perform action with word document, it work only with the main document, not work with endnote, so to make it work with footnote or endnote your need to detect it and switch the document view. In the next article, I will show how to switch the document views in word document.

0 comments :

Post a Comment