-5

A friend of mine made this Excel VBA code for me a while ago. It's 32bit, but now I need it converted for 64bit.

Can anyone please help me to do so?

Private Declare Function FindWindow Lib "user32" _
                     Alias "FindWindowA" ( _
                             ByVal lpClassName As String, _
                             ByVal lpWindowName As String) As Long

Private Declare Function GetWindowLong Lib "user32.dll" _
                     Alias "GetWindowLongA" ( _
                             ByVal hWnd As Long, _
                             ByVal nIndex As Long) As Long

Private Declare Function SetWindowsHookEx Lib "user32" _
                     Alias "SetWindowsHookExA" ( _
                             ByVal idHook As Long, _
                             ByVal lpfn As Long, _
                             ByVal hmod As Long, _
                             ByVal dwThreadId As Long) As Long

Private Declare Function CallNextHookEx Lib "user32" ( _
                             ByVal hHook As Long, _
                             ByVal nCode As Long, _
                             ByVal wParam As Long, _
                             lParam As Any) As Long

Private Declare Function UnhookWindowsHookEx Lib "user32" ( _
                             ByVal hHook As Long) As Long

Private Declare Function PostMessage Lib "user32.dll" _
                     Alias "PostMessageA" ( _
                             ByVal hWnd As Long, _
                             ByVal wMsg As Long, _
                             ByVal wParam As Long, _
                             ByVal lParam As Long) As Long

Private Declare Function WindowFromPoint Lib "user32" ( _
                             ByVal xPoint As Long, _
                             ByVal yPoint As Long) As Long

Private Declare Function GetCursorPos Lib "user32.dll" ( _
                             ByRef lpPoint As POINTAPI) As Long
Gilles
  • 9,269
  • 4
  • 34
  • 53
Ahmad Abbas
  • 11
  • 1
  • 6
  • 1
    This should point you safely in the right direction: https://msdn.microsoft.com/en-us/library/office/ee691831(v=office.14).aspx – Ambie Nov 06 '15 at 11:24
  • 1
    Possible duplicate of [Excel VBA Code: Compile Error in x64 Version ('PtrSafe' attribute required)](http://stackoverflow.com/questions/16763147/excel-vba-code-compile-error-in-x64-version-ptrsafe-attribute-required) – mauek unak Nov 06 '15 at 11:31
  • Please edit question and describe the specific problem you have. What doesn't work on 64 bits with that code ? – kebs Nov 06 '15 at 11:46
  • So you can open my VBA projects on x64 machines too? No thanks :) - Also, unless your friend's name is Siwom, and he is a Vietnamese developer - I don't think he wrote this code for you! – SierraOscar Nov 06 '15 at 12:12

2 Answers2

1

You need to use "PtrSafe" when declaring function :

Private Declare PtrSafe  Function 

Also in 64bit Excel, use LongLong instead of Long

mauek unak
  • 702
  • 2
  • 11
  • 28
0

and LongPtr for callback functions

but for ptrSafe compiler itself will warn you if this is missing

tsolina
  • 141
  • 15