Screen Flip Flop with VBA

Written by Allen Wyatt (last updated January 17, 2020)
This tip applies to Word 97, 2000, 2002, and 2003


2

There are many, many times when I work with two files at a time in Word. For instance, I may be reading one document and comparing it to another (and I don't want to use the Compare Documents feature). I always try to keep the document I am modifying in the top part of my screen, and the other document in the bottom part. Call it a personality quirk, but I find it easier to use the windows this way.

It can be a pain to repeatedly adjust the position of the windows and make sure that the proper file is at the top of the screen. Therefore, I developed a macro to handle this situation. You can use this handy little macro to switch which window is "on top" if you have two windows displayed on the screen. You will probably want to assign this to a toolbar button or a shortcut key, as it will be of little use if you need to keep calling it from the macro list. The following will work in Word 97:

Sub FlipFlop()
    If Windows.Count = 2 Then
        WordBasic.NextWindow
        WindowArrangeAll
    End If
End Sub

If you are using a later version of Word, then macro needs to changed just slightly:


Sub FlipFlop()
If Windows.Count = 2 Then
    WordBasic.NextWindow
    Windows.Arrange
End If
End Sub

Notice that these macros only work if (and only if) there are two windows on the screen. If there is more or less, then the macro does nothing at all.

There are undoubtedly VBA experts reading this tip who will notice right away that the command WordBasic.NextWindow could have been replaced with ActiveWindow.Next.Activate. (The VBA help indicates this is the VBA equivalent of the NextWindow command in WordBasic.) An interesting thing happens when you do this, however—the macro does not work. You can try this yourself by following these steps:

  1. Create two document windows on the screen. (Open two Word documents, and only two.)
  2. Choose Arrange All from the Window menu.
  3. Now start recording a macro; you can give it any name you want.
  4. Press Ctrl+F6, which makes the next window active.
  5. Choose Arrange All from the Window menu.
  6. Repeat steps 4 and 5 for two more iterations.
  7. Stop the macro recorder.
  8. Run the macro you just created.

When you do these steps, you will notice that the macro (the one that Word just created for you) bombs out on one of the ActiveWindow.Next.Activate commands. Probably a good bug item for Redmond, but the way around it is to use the WordBasic.NextWindow command instead.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (972) applies to Microsoft Word 97, 2000, 2002, and 2003.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Printing Odd or Even Pages

You can instruct Word, when printing your document, to print only the odd- or even-numbered pages. This tip explains how ...

Discover More

Calculating Averages by Date

When you have a huge amount of daily data to analyze, you may want to calculate an average of values for any given date ...

Discover More

Making Wider Footer Margins

Want the margins used in your footers (or headers) to be wider than the margins used in the rest of your document? There ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More WordTips (menu)

Clearing the Undo Stack in a Macro

When writing a macro, you may need a way to clear the undo stack. This can be done with a single command, as described in ...

Discover More

Understanding the For ... Next Structure

Spend any time creating Word macros, and sooner or later you will need to repeat some of your programming code a certain ...

Discover More

Moving Through a Table in a Macro

Do you need to step through a table, cell by cell, in a macro? It's easy to do using the Move method, as described in ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 7 - 7?

2015-07-20 09:49:27

Alana

Wow and thanks Allen; very much appreciated! I’m new to VBA in Word and Excel, and this was perfect in Word! Haven’t done macros in over 2 decades and needed to jump back on it.


2015-06-02 13:43:59

Tom Bates

Good find!


This Site

Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.