WD2000: Macro to Return to the View You Were Using Before Opening Header or Footer (212638)



The information in this article applies to:

  • Microsoft Word 2000

This article was previously published under Q212638

SUMMARY

When you run a recorded macro that opens, modifies, and closes the header or footer, you are returned to page layout view when the macro finishes, regardless of which document view you were using before you ran the macro. By removing (commenting) an If...Then statement and adding three lines to the recorded macro, you can modify the macro to return to the view you were in before you ran the macro.

The "More Information" section of this article explains how to use this example macro.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
For more information about how to use the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:

212536 OFF2000: How to Run Sample Code from Knowledge Base Articles

To return to the document view that you were using before you ran the macro, use a Visual Basic for Applications macro that adds the following functionality:
  • Dimensions a variable to hold the current view
  • Saves the current view into the variable
  • Restores the original view when the macro finishes
    Sub ViewHeaderFooterExample()
    
       ' Add this line that dimensions a variable to the recorded macro
       ' to store the current view.
       Dim OriginalView As Long
       
       ' Existing lines in the recorded macro.
       If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
          ActiveWindow.Panes(2).Close
       End If
    
       ' Add this line that captures the current view to the recorded macro.
       OriginalView = ActiveWindow.ActivePane.View.Type
    
       ' Remove or comment the following lines in the recorded macro. Note
       ' only three lines are removed or commented. Do not remove or comment
       ' the third line from the following If...End If macro code.
    
       ' If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
       '     ActivePane.View.Type = wdOutlineView Then
                ActiveWindow.ActivePane.View.Type = wdPrintView
       ' End If
    
       ' Existing lines in the recorded macro.
       ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
       ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    
       ' Add this line that returns the view to the original view to
       ' the recorded macro.
       ActiveWindow.ActivePane.View.Type = OriginalView
    
    End Sub
    					

REFERENCES

For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:

212623 WD2000: Macro Programming Resources

226118 OFF2000: Programming Resources for Visual Basic for Applications


Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbdtacode kbhowto kbinfo kbmacroexample kbnofix KB212638