Excel Macro Help: Is it possible to stop the movement of the mouse pointer for a specific time??

Anonymous
2015-08-24T10:06:25+00:00

Hi all,

Is it possible to stop the movement of the mouse pointer for a specific time using an Excel Macro??

The macro should accept the mouse movement stoppage time from the user using a dialog box.

Is that possible. Please help..

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. Anonymous
    2015-08-24T13:17:21+00:00

    Hi,

    I think it is not possible, at least I didn't find a way to do it.

    Following code reads the prosition of the cursor, hide it for the given amount of time and place it back where it was.

    Run ActivateMain to activate Main, giving some time to move to the Excel sheet.

    Option Explicit

    Private Type POINTAPI

            x As Long

            y As Long

    End Type

    #If VBA7 Then

       Private Declare PtrSafe Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long

       Private Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

       Private Declare PtrSafe Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long

    #Else

       Private Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long

       Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

       Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long

    #End If

    Sub Main()

       Dim CurPos As POINTAPI

       Dim intStopSec As Integer

       GetCursorPos CurPos

       intStopSec = Application.InputBox(Prompt:="Stop cursor movement", Default:=30)

       ShowCursor False

       Application.Wait Now + TimeSerial(0, 0, intStopSec)

       SetCursorPos CurPos.x, CurPos.y

       ShowCursor True

    End Sub

    Sub ActivateMain()

       Application.OnTime Now + TimeValue("00:00:05"), "Main"

    End Sub

    0 comments No comments
Answer accepted by question author
  1. Anonymous
    2015-08-24T12:43:38+00:00

    Hi,

    Try any of the following functions:

    Sub stopMouse()

        Application.Interactive = False

        Application.Wait Now + TimeValue("00:00:30")

        Application.Interactive = True

    End Sub

    Sub setCursorBusy()

        Application.Cursor = xlWait

        Application.Wait Now + TimeValue("00:00:30")

        Application.Cursor = xlDefault

    End Sub

    Cheers,

    Kish+

    0 comments No comments

0 additional answers

Sort by: Most helpful