Microsoft KB Archive/189054

= XL98: Visual Basic Example for Using SpinButton with a Date =

Article ID: 189054

Article Last Modified on 6/17/2005

-

APPLIES TO


 * Microsoft Excel 98 for Macintosh

-



This article was previously published under Q189054



SUMMARY
In Microsoft Excel 98, you can use a spin button on a user form to change values on a worksheet or in a Visual Basic procedure. Microsoft Visual Basic for Applications provides the ability to attach procedures to object events.



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. The following Visual Basic procedure shows you how to use a spin button control to increment and decrement a date value. To create and run this procedure, follow these steps:  Open or create a new workbook in Microsoft Excel 98, and start the Visual Basic Editor by pressing OPTION+F11. Create the user form.

 On the Insert menu, click UserForm. Click the TextBox control from the Toolbox. Insert a text box (TextBox1) on the user form (UserForm1). Click the SpinButton control from the Toolbox. Insert a spin button (SpinButton1) on the user form (UserForm1). Click the CommandButton control from the Toolbox. Insert a command button (CommandButton1) on the user form (UserForm1).</ol> </li> On the View menu, click Properties Window.</li> Type new captions for the form objects.

<ol style="list-style-type: lower-alpha;"> Click the command button. Click the Caption, type Close Now, and press RETURN.

NOTE: This places the text on the command button.</li> Click to select the form. In the Properties Window, click Caption, type Change Date, and press RETURN.</li></ol> </li> Type the code for the objects, and follow these steps:

<ol style="list-style-type: lower-alpha;">  Click to select the command button. On the View menu, click Code. Two lines of code are automatically entered for you. Between those two lines, type the following: UserForm1.Hide </li> On the Window menu, click "UserForm1 (UserForm)."</li> On the user form, click the spin button. On the View menu, click Code.</li>  Ensure that the Object list (the list in the upper left side of the window) shows SpinButton1. Click the Procedures list (the list in the upper right of the window) and select SpinDown. Type the following code between the two lines placed automatically on the sheet: UserForm1.TextBox1.Text = DateValue(UserForm1.TextBox1.Text) - 1 </li>  Click the Procedures list and select SpinUp. Type the following code between the two lines of code placed automatically on the sheet: UserForm1.TextBox1.Text = DateValue(UserForm1.TextBox1.Text) + 1 </li></ol> </li>  On the Insert menu, click Module. On the module sheet, type the following code: Sub ShowForm UserForm1.TextBox1.Text = Date UserForm1.Show End Sub </li> On the Tools menu, click Macros. In the Macros dialog box, click ShowForm and then click Run.</li></ol>

The user form is displayed. Click the up arrow to increment the date,and click the down arrow to decrement the date. To close the user form and return to the Microsoft Visual Basic Editor, click Close Now.

<div class="references_section">