Macro - Passage de 32 bits à 64 bits - Merci de

Bonjour à tous !

J'ai récupéré sur Internet un programme qui simule un mouvement de souris.

Je ne suis pas doué en VBA. J'ai copié collé dans un projet VBA, créé 2 boutons SleeperFunk and StopAllMacro. Lors de l'exécution, j'obtiens un message qui m'informe qu'il faut transformer le script pour le passer en 64 bits. J'ai alors remplacé la décalartion des fonctions avec des PtrSafe et des Long -> LongPtr.

Ensuite, j'ai obtenu un message qui m'indique sur les 4 CONST ci-après ne peuvet pas être Public. Bref, après 2 J de recherche, j'ai besoin d'aide.

D'avance merci de votre aide

Sébastien

Voiçi le code original :

Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal Milliseconds As LongPtr)

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

Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)

Public Const MOUSEEVENTF_LEFTDOWN = &H2

Public Const MOUSEEVENTF_LEFTUP = &H4

Public Const MOUSEEVENTF_RIGHTDOWN As Long = &H8

Public Const MOUSEEVENTF_RIGHTUP As Long = &H10

Public Sub SingleClick()

If ThisWorkbook.Sheets("Links").Range("V5") = "MouseClick Run" Then

mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0

mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0

Call SleeperFunk

Else

End

End If

End Sub

Public Sub SleeperFunk()

ThisWorkbook.Sheets("Links").Range("V5") = "MouseClick Run"

Application.OnTime Now + TimeValue("00:00:10"), "SingleClick"

'Sleep (5000)

End Sub

Public Sub StopAllMacro()

'change reference cell, to stop the mouse click

ThisWorkbook.Sheets("Links").Range("V5") = "Stop AutoClick"

End Sub

Bonjour et

Pense à poster un fichier.

Essaie ces fonctions-ci :

#If Win64 Then 'si version Excel 2010 ou 2013 et 64 bits
    Declare PtrSafe Sub ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI)
    Declare PtrSafe Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, _
                                                  ByVal cButtons As Long, ByVal dwExtraInfo As Long)
    Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Declare PtrSafe Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
#Else
    Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
    Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, _
                                          ByVal cButtons As Long, ByVal dwExtraInfo As Long)
    Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
#End If

Public Const MOUSEEVENTF_MOVE = &H1
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Public Const MOUSEEVENTF_RIGHTDOWN = &H8
Public Const MOUSEEVENTF_RIGHTUP = &H10
Public Const MOUSEEVENTF_MIDDLEDOWN = &H20
Public Const MOUSEEVENTF_MIDDLEUP = &H40
Public Const MOUSEEVENTF_ABSOLUTE = &H8000

repris dans cet exemple (j'espère que cela fonctionnera !!)

147mouse.xlsm (20.63 Ko)

Merci beaucoup Steelson pour votre retour très rapide, la correction et le fichier Excel.

Je vais tester !

MERCI !!

Sébastien

Testé avec succès, encore un grand merci de votre aide !

Le code a été corrigé, puis considérablement amélioré par votre intervention

Sébastien

Parfait !

Rechercher des sujets similaires à "macro passage bits merci"