Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

XL2000: Visual Basic Example for Using a Spin Button with a Date


View products that this article applies to.

Summary

In Microsoft Excel 2000, you can use a SpinButton control on a UserForm to change values on a worksheet or in a Visual Basic procedure. Microsoft Visual Basic for Applications in Excel 2000 provides the ability to attach procedures to object events such as clicking on the DOWN ARROW of the spin button (SpinDown event) and clicking on the UP ARROW (SpinUp event).

↑ Back to the top


More information

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/30000104

Microsoft 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:
  1. From a new workbook in Microsoft Excel 2000, press ALT + F11 to start the Visual Basic Editor.
  2. In the Microsoft Visual Basic Editor, click Insert, and then select UserForm.
  3. Click the TextBox tool in the Controls Toolbox. Place a text box (TextBox1) on the UserForm.
  4. Click the SpinButton tool in the Controls Toolbox. Place a spin button (SpinButton1) on the UserForm.
  5. Click the CommandButton tool in the Controls Toolbox. Place a command button (CommandButton1) on the UserForm.
  6. On the View menu, click Properties Window.
  7. With CommandButton1 selected, click Caption, type Close Now, and then press ENTER. This places the text on the command button.
  8. Select the UserForm by clicking anywhere on the form. In the Properties window, click Caption, type Change Date, and then press ENTER.
  9. 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:
    UserForm1.Hide
    					
  10. Double-click UserForm1 (UserForm) on the Window menu to return to the UserForm.
  11. On the UserForm, right-click the SpinButton, and then click View Code.
  12. 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
    					
  13. 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
    					
  14. 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
    					
  15. 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.

↑ Back to the top


References

For more information about the SpinButton control, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type SpinButton control in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

↑ Back to the top


Keywords: KB213224, kbprogramming, kbinfo, kbhowto, kbdtacode

↑ Back to the top

Article Info
Article ID : 213224
Revision : 8
Created on : 11/23/2006
Published on : 11/23/2006
Exists online : False
Views : 280