Encountering Run time error 435 can’t find dll entrypoint GetCursorPos in user 32 when operating on MOUSEEVENTS.

  • MODERATOR NOTICE: This topic has also been posted on other sites and may already have an answer elsewhere. Please take this into consideration when answering this question

    I am trying to create a basic excel macro sheet for my use but I get “ Run time error 435 can’t find DLL entry point GetCursorPos in user 32 “ when I try to run the following code :

    I got this code off the web. I have little knowledge of coding and I’m totally novice to VBA.

    Also as an alternative, I tried another code a smaller version which does less than the above one

    Code
    1. Public Declare PtrSafe Function SetCursorPos Lib "User32" (ByVal x As Long, ByVal y As Long) As Long
    2. Public Declare PtrSafe Sub mouse_event Lib "User32" (ByVal dwflag As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButton As Long, ByVal dextrainfo As Long)
    3. Public Const MOUSEEVENTF_RIGHTDOWN = &H2
    4. Public Const MOUSEEVENTF_RIGHTUP = &H4
    5. Sub MOUSECLICK()
    6. SetCursorPos 200, 55
    7. mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0
    8. mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
    9. End Sub


    This one too ends up with “ Run time error 435 can’t find DLL entry point SetCursorPos in user 32 “


    The system which I tried these codes on is running on Win 10 enterprise which has office 365. However, when I tried it on two different machines running on Win 7 and 8 (office 2010 on both ) it runs perfectly fine. I even toned down the macro security settings to enable all macros and trust access to the VBA project object model for the Win 10.


    Basically, these codes operate the mouse cursor with the help of macros.

    What could be the reason I get this error? Is this because of Antivirus?


    Is there any other way to do this without using a third-party app installation?

    Please provide any solutions.