Friday, March 14, 2014

How to switch from main view to Endnote view

Leave a Comment


As I mentioned in the previous article, to make vba code work with endnote or footnote we need to switch the view to endnote or footnote view. In this article I show the code for switching view of word document.

How to switch the view to endnote view
First I use the function EndnotesExist to check whether there is endnote exists in the word document and then use ActiveWindow.ActivePane.View.Type to switch the view


≫ Detect Endnote
FunctionEndnotesExist() As Boolean
    DimStoryRange As Range
    ForEach StoryRange In ActiveDocument.StoryRanges
        IfStoryRange.StoryType = wdEndnotesStory Then
            EndnotesExist = True
            ExitFor
        End If
    Next StoryRange
EndFunction



Full code
PublicSub ChangeFormatInEndnote()
   
    IfEndnotesExist = TrueThen
        ' switch body to endnotes
        IfActiveWindow.ActivePane.View.Type = wdPrintView Or ActiveWindow. _
            ActivePane.View.Type = wdWebView Or ActiveWindow.ActivePane.View.Type = _
            wdPrintPreview Then
                ActiveWindow.View.SeekView = wdSeekEndnotes
        Else
            ActiveWindow.View.SplitSpecial = wdPaneEndnotes
        End If
       
        ' Macro in endnote
        Selection.WholeStory
        'Put your Change Function Here
       
        IfActiveWindow.ActivePane.View.Type = wdPrintView Or ActiveWindow. _
            ActivePane.View.Type = wdWebView Or ActiveWindow.ActivePane.View.Type = _
            wdPrintPreview Then
                ActiveWindow.View.SeekView = wdSeekMainDocument
        Else
            ActiveWindow.Panes(2).Close
        End If
    End If
   
    Selection.WholeStory
    'Put your Function Here
   
EndSub

0 comments :

Post a Comment

DMCA.com Protection Status