Just a trivial bit of code to save and restore the mousepointer.
It's quite common to set the mousepointer to an hourglass at the start of a long procedure, then set it back to default when you exit.
But how do you know it was in the default state when your procedure was called? It may have been called from another time-consuming procedure that had already set it to the hourglass - which will not want it sent back as the default.
Of course you can do this:
VB Code:
Sub MySub() Dim iOldMousePointer As Integer iOldMousePointer = Screen.MousePointer Screen.MousePointer = vbHourglass 'Do lots of stuff....... Screen.MousePointer = iOldMousePointer End Sub
But it's a lot less typing to do this:
VB Code:
Sub MySub() PushP 'Do lots of stuff....... PopP End Sub
Just add this to a module:
VB Code:
Option Explicit 'Store pushed and popped mouse pointers Private ScreenMousePointers As String Public Sub PushP() 'Saves the screen mousepointer then sets it to an hourglass ScreenMousePointers = Format$(Screen.MousePointer, "00") & ScreenMousePointers Screen.MousePointer = vbHourglass End Sub Public Sub PopP() 'Restores the screen mousepointer to what it was before pushp was called Dim s As String Screen.MousePointer = Val(Left$(ScreenMousePointers, 2)) ScreenMousePointers = Mid$(ScreenMousePointers, 3) End Sub
Using Exit Sub in the middle of your procedure will mess it up of course, but that's not good practice anyway and I'm sure you never do it :)
The pushes and pops must be in pairs and in the right order, but if you screw up nothing dramatic happens except you get the wrong mousepointer.
Enjoy!
