Microsoft provides programming examples for illustration only, without warranty either
expressed or implied, including, but not limited to, the implied warranties of
merchantability and/or fitness for a particular purpose. This article assumes
that you are familiar with the programming language being demonstrated and the
tools used to create and debug procedures. Microsoft support professionals 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 needs.
If you have limited programming experience, you may
want to contact a Microsoft Certified Partner or Microsoft Advisory Services. For more information, visit these Microsoft Web sites:
Microsoft Certified
Partners -
https://partner.microsoft.com/global/30000104Microsoft Advisory Services -
http://support.microsoft.com/gp/advisoryservice
For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:
http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS
To use a SpinButton control to both increment and decrement a date value in an edit box, follow these steps:
- From a new workbook in Microsoft Excel 2000, press ALT + F11 to start the Visual Basic Editor.
- In the Microsoft Visual Basic Editor, click Insert, and then select UserForm.
- Click the TextBox tool in the Controls Toolbox. Place a text box (TextBox1) on the UserForm.
- Click the SpinButton tool in the Controls Toolbox. Place a spin button (SpinButton1) on the UserForm.
- Click the CommandButton tool in the Controls Toolbox. Place a command button (CommandButton1) on the UserForm.
- On the View menu, click Properties Window.
- With CommandButton1 selected, click Caption, type Close Now, and then press ENTER. This places the text on the command button.
- Select the UserForm by clicking anywhere on the form. In the
Properties window, click Caption, type Change Date, and then press ENTER.
- Right-click the command button, and then click View Code. Two lines of code are automatically entered for you. Between those two lines, type the following:
- Double-click UserForm1 (UserForm) on the Window menu to return to the UserForm.
- On the UserForm, right-click the SpinButton, and then click View Code.
- Ensure that the Object list box (the drop-down list box in the upper-left of the window) shows SpinButton1. Click the
Procedures list box (the drop-down list box 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
- Click the Procedures list box, and then 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
- In the Visual Basic Editor, click Insert, and then click Module. On the module sheet, type the following code:
Sub ShowForm()
UserForm1.TextBox1.Text = Date
UserForm1.Show
End Sub
- In the Visual Basic Editor, click Tools, and then click Macros.
In the Macros dialog box, click ShowForm, and then click Run.
The UserForm appears. Click the UP ARROW to increment the date. Click the DOWN ARROW to decrement the date. Click the
Close Now button to close the UserForm, and then return to the Visual Basic Editor.