Use the drop-down list on the left (labeled Choose Commands From) to display various groups of commands.



Locate the command in the list box on the left and select it.

Use the drop-down list on the right (labeled Customize The Ribbon) to choose a group of tabs.

Literature

1. Джон Уокенбах, Excel VBA Programming For Dummies 5 августа 1999 г.

2. Джон Мюллер, VBA for dummies 2003 г.

3. Ричард Мансфилд, Mastering VBA for Microsoft Office 2007 2008 г.

4. Билл Джелен, Трейси Сирстад, Excel 2013 VBA and Macros 2013 г

5. Ричард Мансфилд, Mastering VBA for Office 2010 2010 г

6. Ричард Шеперд, Excel 2007 VBA Macro Programming 2009 г

7.  Майк Мак-Грат, EXCEL VBA IN EASY STEPS. 2017 г.

 

Lecture № 14.    Simple Dialog Boxes

In This Chapter

1.  Saving time by using any of several alternatives to UserForms

2.  Using the InputBox and MsgBox functions to get information from the user

 

Уou can’t use Excel very long without being exposed to dialog boxes. They seem to pop up all the time. Excel — like most Windows programs — uses dialog boxes to obtain information, clarify commands, and display messages. If you develop VBA macros, you can create your own dialog boxes that work just like those built into Excel. Those custom dialog boxes are called UserForms in VBA. This chapter doesn’t tell you anything about creating UserForms. Rather, it describes some techniques you might be able to use in place of UserForms. Chapters 16 through 18, however, do cover UserForms.

 

UserForm Alternatives

Some of the VBA macros you create behave the same every time you execute them. For example, you may develop a macro that enters a list of your employees into a worksheet range. This macro always produces the same result and requires no additional user input.

 

You might develop other macros, however, that behave differently under various circumstances or that offer the user options. In such cases, the macro may benefit from a custom dialog box. A custom dialog box provides a simple means for getting information from the user. Your macro then uses that information to determine what it should do.

UserForms can be quite useful, but creating them takes time. Before I cover the topic of creating UserForms in the next chapter, you need to know about some potentially timesaving alternatives.

 

VBA lets you display several different types of dialog boxes that you can sometimes use in place of a UserForm. You can customize these built-in dialog boxes in some ways, but they certainly don’t offer the options available in a UserForm. In some cases, however, they’re just what the doctor ordered.

 

In this chapter, you read about

 

✓ The MsgBox function

✓ The InputBox function

✓ The GetOpenFilename method

✓ The GetSaveAsFilename method

✓ The FileDialog method

 

I also describe how to use VBA to display some of the Excel built-in dialog boxes — the dialog boxes that Excel uses to get information from you.

 

 

The MsgBox Function

You’re probably already familiar with the VBA MsgBox function — I use it quite a bit in the examples throughout this book. The MsgBox function,

which accepts the arguments shown in Table 15-1, is handy for displaying information and getting simple user input. It’s able to get user input because it’s a function. A function, as you recall, returns a value. In the case of the MsgBox function, it uses a dialog box to get the value that it returns. Keep reading to see exactly how it works.

Displaying a simple message box

You can use the MsgBox function in two ways:

 

To simply show a message to the user. In this case, you don’t care about the result returned by the function.

To get a response from the user. In this case, you do care about the result returned by the function. The result depends on the button that the user clicks.

 

If you use the MsgBox function by itself, don’t include parentheses around the arguments. The following example simply displays a message and does not return a result. When the message is displayed, the code stops until the user clicks OK.

Figure 15-1 shows how this message box looks. In this case, printing commences when the user clicks OK. Notice that there is no way to cancel the printing? The next section describes how to fix that.

Literature

1. Джон Уокенбах, Excel VBA Programming For Dummies 5 августа 1999 г.

2. Джон Мюллер, VBA for dummies 2003 г.

3. Ричард Мансфилд, Mastering VBA for Microsoft Office 2007 2008 г.

4. Билл Джелен, Трейси Сирстад, Excel 2013 VBA and Macros 2013 г

5. Ричард Мансфилд, Mastering VBA for Office 2010 2010 г

6. Ричард Шеперд, Excel 2007 VBA Macro Programming 2009 г

7.  Майк Мак-Грат, EXCEL VBA IN EASY STEPS. 2017 г.

 


Дата добавления: 2019-03-09; просмотров: 184; Мы поможем в написании вашей работы!

Поделиться с друзьями:






Мы поможем в написании ваших работ!