XL: Controlling Appearance of Mouse Pointer Within Macro

Last reviewed: September 2, 1997
Article ID: Q130044

The information in this article applies to:

  • Microsoft Excel for Windows 95, version 7.0
  • Microsoft Excel 97 for Windows

SUMMARY

In Microsoft Excel versions 97 and 7.0, you can use the Visual Basic for Applications Cursor property to control the appearance of the mouse pointer while a macro is running. In earlier versions of Microsoft Excel, you do not have this ability to change the way the mouse pointer is displayed.

MORE INFORMATION

In Microsoft Excel version 5.0, the mouse pointer is normally displayed as an hourglass when you run a macro. The exception to this is when you run a macro from a control in a custom dialog box. In this case, the mouse pointer continues to be displayed as an arrow, and does not give you an indication that the macro (event procedure) is running.

In Microsoft Excel versions 7.0 and 97, you can use the Cursor property to display the mouse pointer as an arrow, an hourglass, an I-beam (displayed when editing text), and the default pointer. The following built-in constants correspond to each of the available cursor shapes:

   xlNorthwestArrow    The northwest-arrow pointer
   xlWait              The hourglass pointer
   xlIBeam             The I-beam pointer
   xlNormal            The default pointer

Note that when you type in the constant for the I-beam pointer, the letter that follows the "xl" prefix is an "I" (for I-beam).

Microsoft provides examples of Visual Basic for Applications procedures 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. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

Cursor Property Example

Sub ChangePointer()

    ' Display dialog box indicating mouse pointer will change
    MsgBox "Click OK to display mouse pointer as hourglass."

    ' Display mouse pointer as hourglass
    Application.Cursor = xlWait

    ' Loop so mouse pointer change will be noticeable
    For x = 1 To 1000
        For y = 1 To 1000
        Next y
    Next x

    MsgBox "Click OK to display mouse pointer as arrow."

    ' Display mouse pointer as arrow
    Application.Cursor = xlNorthwestArrow

    ' Loop so mouse pointer change will be noticeable
    For x = 1 To 1000
        For y = 1 To 1000
        Next y
    Next x

    MsgBox "Click OK to display mouse pointer as I-beam."

    ' Display mouse pointer as I-beam
    Application.Cursor = xlIBeam

    ' Loop so mouse pointer change will be noticeable
    For x = 1 To 1000
        For y = 1 To 1000
        Next y
    Next x

    MsgBox "Click OK to return mouse pointer to normal."

    ' Return mouse pointer to normal display
    Application.Cursor = xlNormal

End Sub

Note that because the Cursor property isn't automatically reset when the macro stops running, you should reset the mouse pointer by setting the Cursor property to the xlNormal value before your macro stops.

REFERENCES

For more information about "Cursor Property," click the Index tab in Help, type the following, and then click Display:

   cursor p


Additional query words: 7.00 8.00 97 XL97
Keywords : PgmOthr kbcode kbhowto kbprg
Version : 7.00 97
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 2, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.