3

I created a macro to do a series of mouse clicks and mouse moves (keystroke macro) to enter repetitive data into Oracle (Program/database).

I used Dataload Classic or Dataloader Classic (keystroke program) to enter data into Oracle before but it lacked the "Smarts", so I created my own keystroke program with some "Smarts".

I am using the SLEEP command/function to wait a couple of seconds/milliseconds after every mouse move and mouse click. Sometimes Oracle would be slow and "pause"/"load"/or "freeze up" and the freezing time might exceed the SLEEP command initial wait time and continue on with the program, thus messing everything up.

example:

if something_happens then
sleep 2000
end if

In DataLoad classic/Dataloader Classic there are options to change how long you can wait/pause for every mouse click or mouse move, etc. There is an "HOURGLASS CHECK". This says you may set a time for the program to wait if the mouse is in the hourglass state and the user may enter millisecond or seconds.

Is there Excel VBA code to check the HOURGLASS state of the mouse?

10
  • 2
    DoEvents? Another DoEvents Link ... Maybe Better Commented Jan 14, 2016 at 20:46
  • What do you mean by the curor state? Where it is in the sheet? If the loading wheel is going, then there's probably a better way to detect something's going on rather than just what the cursor animation is showing. Commented Jan 14, 2016 at 20:46
  • I am writing it in the module, I've been searching online but I am not finding anything. Maybe I'm not searching for the right terms @BruceWayne Commented Jan 15, 2016 at 12:51
  • 2
    Our main question here is why are you checking the cursor for some action? This sounds like it could be an XY problem. I think your "real" question here is how to determine when a loop is complete (when the mouse would stop being the hourglass)? Commented Jan 15, 2016 at 14:46
  • 1
    There is an "Application.Cursor" property. Have you tried that? As a test, something like: If Application.Cursor = xlWait Then MsgBox "foo" You could probably wrap a check in a "Do While" loop. Here is the MSDN documentation: msdn.microsoft.com/en-us/library/office/… Commented Jan 18, 2016 at 16:23

2 Answers 2

3
+100

You could try the following function which uses win api functions LoadCursor and GetCursorInfo to determine if the current cursor equals to wait cursor.

The function first loads the win-predefined wait cursor then gets current cursor and checks if they are the same. HTH

Option Explicit

Private Const IDC_WAIT As Long = 32514

Private Type POINT
    x As Long
    y As Long
End Type

Private Type CURSORINFO
    cbSize As Long
    flags As Long
    hCursor As Long
    ptScreenPos As POINT
End Type

Private Declare Function GetCursorInfo _
    Lib "user32" (ByRef pci As CURSORINFO) As Boolean
Private Declare Function LoadCursor _
    Lib "user32" Alias "LoadCursorA" _
    (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long

Public Function IsWaitCursor() As Boolean

    ' Get handle to wait cursor
    Dim handleWaitCursor As Long
    handleWaitCursor = LoadCursor(ByVal 0&, IDC_WAIT)

    Dim pci As CURSORINFO
    pci.cbSize = Len(pci)

    ' Retrieve information about the current cursor
    Dim ret As Boolean
    ret = GetCursorInfo(pci)

    If ret = False Then
        MsgBox "GetCursorInfo failed", vbCritical
        Exit Function
    End If

    ' Returns true when current cursor equals to wait cursor
    IsWaitCursor = (pci.hCursor = handleWaitCursor)

End Function
Sign up to request clarification or add additional context in comments.

Comments

0

Try checking screen.MousePointer property if Busy (Hourglass)

While screen.MousePointer = 11
      Sleep(500)
Wend

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.