Change mouse pointer with VBA

Use this space to ask how to do whatever you're trying to use SolidWorks to do.
Jacomuller
Posts: 47
Joined: Wed Mar 01, 2023 6:55 pm
Answers: 2
x 33
x 4

Change mouse pointer with VBA

Unread post 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.
User avatar
JSculley
Posts: 638
Joined: Tue May 04, 2021 7:28 am
Answers: 55
x 9
x 868

Re: Change mouse pointer with VBA

Unread post by JSculley »

Jacomuller
Posts: 47
Joined: Wed Mar 01, 2023 6:55 pm
Answers: 2
x 33
x 4

Re: Change mouse pointer with VBA

Unread post 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.
User avatar
SPerman
Posts: 2035
Joined: Wed Mar 17, 2021 4:24 pm
Answers: 14
x 2207
x 1860
Contact:

Re: Change mouse pointer with VBA

Unread post by SPerman »

Someone asked the same question in the old forum. I don't see an answer.

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
User avatar
JSculley
Posts: 638
Joined: Tue May 04, 2021 7:28 am
Answers: 55
x 9
x 868

Re: Change mouse pointer with VBA

Unread post 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
Post Reply