2016-01-14 16 views
3

您好我已經創建了一個宏,它會執行嚴重的鼠標點擊和鼠標移動(按鍵宏),以將大量重複數據輸入Oracle(程序/數據庫)。我使用Dataload Classic或Dataloader Classic(按鍵程序)將數據輸入到oracle,但缺少「Smarts」,因此我創建了自己的帶有「Smarts」的按鍵程序。在excel vba 2013中獲取遊標狀態

現在我正在使用SLEEP命令/函數在每次鼠標移動和鼠標單擊後等待幾秒/毫秒,但問題是有時Oracle會很慢並且「暫停」/「加載」/或「凍結並且凍結時間可能會超過SLEEP命令的初始等待時間,並繼續執行程序,從而搞砸了一切。

例如:

如果something_happens然後
睡眠2000
結束時,如果

在數據加載經典/的DataLoader經典,有選項可以更改多久,你可以等待/暫停爲每次鼠標點擊或鼠標等。最讓我感興趣的是「HOURGLASS CHECK」選項。這個小時的玻璃檢查表明,如果鼠標仍然處於沙漏狀態,您可以設置程序等待的時間。當然用戶可以輸入毫秒或秒。

Excel VBA中是否有任何代碼可以檢查鼠標狀態的這個HOUR GLASS?睡眠命令是不夠的,我需要這個小時玻璃檢查我的程序。請幫助我解決這個難題。

預先感謝您

+2

[的DoEvents](https://msdn.microsoft.com/en-us/library/aa262728(五= vs.60)的.aspx)? [另一個DoEvents鏈接...也許更好](https://support.microsoft.com/en-us/kb/118468) –

+0

你是什麼意思的cur州?它在哪裏?如果裝載輪正在進行,那麼可能有更好的方法來檢測正在發生的事情,而不僅僅是光標動畫顯示的內容。 – BruceWayne

+0

我正在寫模塊,我一直在網上搜索,但我沒有找到任何東西。也許我不是在尋找合適的術語@BruceWayne – Proggie

回答

3

你可以試試下面的函數,它使用贏API功能LoadCursorGetCursorInfo以確定當前光標等於等待光標。

函數首先加載win-defined等待遊標,然後獲取當前遊標並檢查它們是否相同。 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 
+0

哇謝謝!你絕對應得的超過100,但這就是我得到的:P – Proggie

+1

不客氣,我很高興它有幫助! – dee

+0

你的代碼奇妙地工作!我會吻你,如果我可以 – Proggie

0

嘗試檢查screen.MousePointer如果屬性忙碌(沙漏)

While screen.MousePointer = 11 
     Sleep(500) 
Wend