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.
Change mouse pointer with VBA
-
- Posts: 51
- Joined: Wed Mar 01, 2023 6:55 pm
- x 36
- x 5
-
- Posts: 51
- Joined: Wed Mar 01, 2023 6:55 pm
- x 36
- x 5
Re: Change mouse pointer with VBA
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.
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
Someone asked the same question in the old forum. I don't see an answer.
https://r1132100503382-eu1-3dswym.3dexp ... 7o6YrLqGuQ
https://r1132100503382-eu1-3dswym.3dexp ... 7o6YrLqGuQ
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
Re: Change mouse pointer with VBA
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: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.
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