Page 1 of 1
Change mouse pointer with VBA
Posted: Sun Jun 16, 2024 10:20 pm
by Jacomuller
I wrote a macro to delete and copy a file on a number of different net work drive locations. This can take up to 45 seconds in which time I don't want the user to fiddle around clicking other stuff. So the idea is to change the mouse pointer to an hourglass at the start of the macro and then to return it to normal at the end of the macro.
So obviously, I have tried the normal "Application.Cursor = xlWait" and "Application.Cursor = xlNormal" without any success.
Re: Change mouse pointer with VBA
Posted: Mon Jun 17, 2024 6:49 am
by JSculley
Re: Change mouse pointer with VBA
Posted: Mon Jun 17, 2024 4:19 pm
by Jacomuller
Thanks @JSculley , was thinking about that, but not sure how to implement it. Normally you would know the total number of actions/events and then show the percentage completed on the status bar. In this case, I want to delete all instances of a file outside the PDM on a network drive and replace it with the new version of the file. So i don't know what the "Max" value is, to display the percentage.
Also, even if can do it, which will be very nice, I would still like to change the mouse pointer for the odd user who is not looking at the status bar, to know that he must wait.
Re: Change mouse pointer with VBA
Posted: Mon Jun 17, 2024 4:58 pm
by SPerman
Someone asked the same question in the old forum. I don't see an answer.
https://r1132100503382-eu1-3dswym.3dexp ... 7o6YrLqGuQ
Re: Change mouse pointer with VBA
Posted: Tue Jun 18, 2024 7:56 am
by JSculley
Jacomuller wrote: ↑Mon Jun 17, 2024 4:19 pm
Thanks @JSculley , was thinking about that, but not sure how to implement it. Normally you would know the total number of actions/events and then show the percentage completed on the status bar. In this case, I want to delete all instances of a file outside the PDM on a network drive and replace it with the new version of the file. So i don't know what the "Max" value is, to display the percentage.
Also, even if can do it, which will be very nice, I would still like to change the mouse pointer for the odd user who is not looking at the status bar, to know that he must wait.
You'll have to call in to the Win32 API to do this then. The relevant functions are LoadCursor, SetCursor and GetCursor. Here's an example that changes the cursor to a wait cursor, pauses for 5 seconds, changes the cursor back to the original cursor and then pauses for another 5 seconds. It also uses the Win32 Sleep function but that's just a convenient way to pause the example code:
Code: Select all
Dim swApp As Object
Const IDC_WAIT = 32514
Dim currentCursor As Long
Dim waitCursor As Long
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Declare PtrSafe Function GetCursor Lib "user32.dll" () As Long
Public Declare PtrSafe Function LoadCursor Lib "user32.dll" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long
Public Declare PtrSafe Sub SetCursor Lib "user32" (ByVal hCursor As Long)
Sub main()
Set swApp = Application.SldWorks
currentCursor = GetCursor
waitCursor = LoadCursor(0, IDC_WAIT)
SetCursor (waitCursor)
Sleep (5000)
SetCursor (currentCursor)
Sleep (5000)
End Sub