Alternatives To Custom Dialog Box
Contents VBA Input Box Syntax & Function The Excel InputBox method Syntax The VBA MsgBox Function The Excel GetOpenFilename Method The Excel GetSaveAsFilename Method Reference
VBA Input Box An input box is a simple dialog box that allows the user to make a single entry. For example, you can use an input box to let the user enter text or a number or even select a range. You can generate an InputBox in two ways: by using a VBA function and by using a method of the Application object.
Syntax & Function InputBox(prompt[,title][,default][,xpos][,ypos][, helpfile, context]) prompt: Required. The text displayed in the InputBox. title: Optional. The caption of the InputBox window. default: Optional. The default value to be displayed in the dialog box. xpos, ypos: Optional. The screen coordinates of the upper-left corner of the window. helpfile, context: Optional. The help file and help topic. The InputBox function prompts the user for a single piece of information. The function always returns a string, so your code may need to convert the results to a value.
The Excel InputBox method Advantages of Excel InputBox over VBA s InputBox: You can specify the data type returned. The user can specify a worksheet range by dragging in the worksheet. Input validation is performed automatically.
Syntax InputBox(Prompt[,Title][,Default][,Left][,To p][,helpfile, HelpContextID][,Type]) Prompt: Required. The text displayed in the input box. Title: Optional. The caption in the input box window. Default: Optional. The default value to be returned by the function if the user enters nothing. Left, Top: Optional. The screen coordinates of the upper-left corner of the window. HelpFile, HelpContextID: Optional. The Help file and Help topic. Type: Optional. A code for the data type returned
The VBA MsgBox Function VBA s MsgBox function is an easy way to display a message to the user or to get a simple response (such as OK or Cancel). Syntax:MsgBox(prompt[,buttons][,title][,helpfil e, context]) prompt: Required. The text displayed in the message box. buttons: Optional. A numeric expression that determines which buttons and icon are displayed in the message box. title: Optional. The caption in the message box window. helpfile, context: Optional. The helpfile and Help topic.
The Excel GetOpenFilename Method If your application needs to ask the user for a filename, you can use the InputBox function. But this approach is tedious and error-prone because the user must type the filename (with no browsing ability). A better approach is to use the GetOpenFilename method of the Application object, which ensures that your application gets a valid filename (as well as its complete path). Syntax: ApplicationGetOpenFilename(FileFilter, FilterIndex, Title, ButtonText, MultiSelect) FileFilter: Optional. A string specifying file-filtering criteria. FilterIndex: Optional. The index number of the default file-filtering criteria. Title: Optional. The title of the dialog box. If omitted, the title is Open. ButtonText: For Macintosh only. MultiSelect: Optional. If True, you can select multiple filenames. The default value is False.
The Excel GetSaveAsFilename Method The GetSaveAsFilename method is very similar to the GetOpenFilename method. It displays a Save As dialog box and lets the user select (or specify) a file. It returns a filename and path but doesn t take any action. Like the GetOpenFilename method, all of the GetSaveAsFilename method s arguments are optional. Syntax:Application.GetSaveAsFilename(InitialFilena me, FileFilter, FilterIndex, Title, ButtonText) The arguments are: InitialFilename: Optional. Specifies the suggested filename. FileFilter: Optional. A string specifying file-filtering criteria. FilterIndex: Optional. The index number of the default filefiltering criteria. Title: Optional. The title of the dialog box. ButtonText: For Macintosh only.
Reference Excel 2010 Power Programming with VBA by John Walkenbach.
THANK YOU