Written by Allen Wyatt (last updated January 13, 2024)
This tip applies to Excel 97, 2000, 2002, and 2003
Andrew needs, in his macro, to display a dialog box that allows a user to switch windows. When someone clicks the Window menu (in Excel), the available workbooks are listed at the bottom of the menu. Those are what Andrew needs to show up in the dialog box. He wonders if there is a built-in dialog box to do this, or if he needs to create his own.
The short answer is that there is no built-in dialog box to accomplish this task. You can, however, easily create your own. Here is a simple example:
Sub SwitchWindows() Dim i As Integer Dim n As Integer Dim s As String Dim v As Variant n = Windows.Count s = "Choose Window from:" For i = 1 To n s = s & Chr(10) & i & ") " & Windows(i).Caption Next s = s & Chr(10) & "Enter a number from 1 to " & n v = Application.InputBox(prompt:=s, Type:=2) i = Val(v) If i >= 1 And i <= n Then Windows(i).Activate End If End Sub
All this does is create a list of the names for each window in your system. It presents them in an InputBox, and then switches to whatever window the user selected.
If you are seeking different ways to present the same information, you can refer to this tip.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11910) applies to Microsoft Excel 97, 2000, 2002, and 2003.
Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!
It is often helpful to get user input within a macro. Here's a quick way to present some options and get the user's response.
Discover MoreSometimes, when you upgrade to a new version of Excel, you could run into a problem recording macros that you had no ...
Discover MoreWhat is a macro? Ever wonder what these are and how to use them? This tip answers the basics of what a macro is used for, ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments