Microsoft KB Archive/212638

= WD2000: Macro to Return to the View You Were Using Before Opening Header or Footer =

Article ID: 212638

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Word 2000 Standard Edition

-



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 

