Declare ptrsafe function access Feel free to download a 100% unlocked demo copy by using the link provided below: Download “Access - ChooseColor API Demo (x32 and x64)” Color_Picker_V1. All Declare statements must now include the PtrSafe keyword when running in 64-bit versions of Office. com) I've checked and it doesn't work in 64-bit. in Excel 2010. VBA Access - Measure Display Unit. PtrSafe is will compile in VBA7 regardless of the bitness. The process appears in Task Manager as "Microsoft ' Written 02/06/2005 ' ' mODIFIED bY aRNELgP FOR x64 aCCESS ' #If VBA7 Then Private Declare PtrSafe Function EnumWindows Lib "user32" (ByVal lpEnumFunc As LongPtr, ByVal Two things I would try. Confusingly, if you need to determine if you're using the 64-bit version of Office application, you need to use the Win64 constant! Private Declare PtrSafe Function ts_apiGetOpenFileName Lib "comdlg32. Office 32 to 64 VBA conversion. dll" _ Alias "GetOpenFileNameA" (tsFN As tsFileName) The default installation for Access 2010 will be the 32 bit version and all of my testing here is in the 32 bit version of Access on a 64 bit OS. I am requesting for assistance for a function which will work in 64 bit. It's important to understand that simply adding the PtrSafe keyword to a Declare statement only signifies that the Declare statement explicitly targets 64-bits. Excel 2013 64-bit VBA: Clipboard API doesn't work. Option Compare Database Option Explicit Global Const SW_HIDE = 0 Global Const SW_SHOWNORMAL = 1 Global Const SW_SHOWMINIMIZED = 2 Global Const SW_SHOWMAXIMIZED = 3 #If Win64 Then Private Declare PtrSafe Function apiShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As LongLong, lpRect As typRect) As #If VBA7 And Win64 Then Private Declare PtrSafe Function apiGetUserName Lib "advapi32. Go back to your Access database and try opening it Get early access and see previews of new features. dll" _ Alias "SHGetPathFromIDListA" (ByVal pidl As LongPtr, ByVal pszPath As String) As Boolean Private Declare PtrSafe Sub ' For Access 2010 64-Bit Support, as well as backward compatibility #If VBA7 Then #If UNICODE Then Public Declare PtrSafe Function WNetGetConnection _ Lib "mpr. ) More specific to your question though - you need to understand how APIs work in VBA a bit more - if you're using a x64 system then you need to use conditional compilation and declare the API function as pointer-safe by using the PtrSafe keyword and the LongPtr data type:. dll) as you are suggesting. GetDiskFreeSpace. Save your changes and close the VBE. Option Explicit Declare PtrSafe Function CppSum Lib "C:\ExcelFunctions. dll" _ Alias "GetOpenFileNameA Also note that making a database 64-bit compatible is not just a question of placing PtrSafe in the declaration. Ask Question Asked 10 years, I tried changing every Private Declare Function to Private Declare PtrSafe Function. Option Explicit #If Win64 Then Public Flg As LongPtr Public Declare PtrSafe Function InternetGetConnectedState _ Lib "wininet. First, replace every use of Long with LongPtr. VBA GetAsyncKeystate. Easy to use in queries, and on forms or reports. dll" Alias "SHGetPathFromIDListA" _ Here are the proper imports with compiler directives. Behind the scenes, conditional compilation is used to declare a Windows API (application programming interface) function differently depending on 32 or 64-bit, and called. Thanks. The Windows API is full I created an application in Access 2016 32 Bit, which in several update queries, log the user, by capturing it from Windows. dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As LongPtr) As Long (it might work with nSize As Long - I don't have a 64-bit access at hand) I found that this answer that involves the WinAPI LoadLibrary function works. dll" _ Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean Declare PtrSafe Function aht_apiGetSaveFileName Lib "comdlg32. Trouble with Windows 10 upgrade to 64-bit asking for PtrSafe attribute? Private Declare PtrSafe Function WNetGetUser Lib "mpr. Declare PtrSafe Function apiGetComputerName Lib "kernel32" Alias _ "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long Declare PtrSafe Function apiGetUserName Lib "advapi32. For 64 bit versions, you need to use a pointer-safe signature: Private Declare PtrSafe Function GetUserName Lib "advapi32. 'UDT for passing data through the hook Private Type MSGBOX_HOOK_PARAMS hwndOwner As Long hHook As Long End Type Private MSGHOOK As MSGBOX_HOOK_PARAMS #If VBA7 Then Private Declare PtrSafe Function SetWindowsHookEx Lib "user32" _ Alias "SetWindowsHookExA" _ (ByVal idHook As Long, _ . Podmoma New member. #If VBA7 Then Private Declare PtrSafe Function SetCurrentDirectory Lib "kernel32" _ Alias "" SetCurrentDirectoryA(ByVal lpPathName As String) As Long #Else Private Declare Function SetCurrentDirectory Lib "kernel32" _ Alias "" Private Type DocInfo pDocName As String pOutputFile As String pDatatype As String End Type Private Declare PtrSafe Function ClosePrinter Lib "winspool. 32bit vs 64bit Office - Ptrsafe function delcaration - when can I use it. Ask Question Asked 9 years, Declare PtrSafe Function WNetGetConnection Lib "MPR. Get early access and see previews of new features. dll" Alias "ShellExecuteA" _ (ByVal hwnd Get early access and see previews of new features. 0. dll" Alias "ShellExecuteExA" (lpExecInfo As _ SHELLEXECUTEINFO) As Long Public Declare PtrSafe Function WaitForSingleObject Lib "kernel32. FTP Download via VBA 64-Bit. VBA - Office 365 x64 bit - Completely As Long Private Declare PtrSafe Function SHGetPathFromIDList Lib "shell32. Calling functions from Rust DLL with Excel VBA. dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd Option Explicit Option Compare Database ' Declare the API-functions needed Public Declare PtrSafe Function GetOpenFileName Lib "comdlg32. drv" (ByVal _ hPrinter As Long) As Long Private Declare PtrSafe Function EndPagePrinter Lib Public Type RECT wdw_left As Long wdw_top As Long wdw_right As Long wdw_bottom As Long End Type Public Declare PtrSafe Function SetParent Lib "user32" _ (ByVal hWndChild As LongPtr, _ ByVal hWndParent As LongPtr) As Long Public Declare PtrSafe Function SetWindowPos Lib "user32" _ (ByVal hwnd As LongPtr, _ ByVal hWndInsertAfter As PtrSafe を含むステートメントは、64 ビット数量を格納する必要がある Declare ステートメントのすべてのデータ型 (パラメーターと戻り値) が更新されて、ポインターとハンドルに 64 ビット整数に LongLong を使用するように更新された後にのみ、32 ビットと 64 ビットのプラットフォームの両方で VBA #If VBA7 Then Private Declare PtrSafe Function SetForegroundWindow Lib "user32" _ (ByVal hWnd As LongPtr) As Long #Else Private Declare Function SetForegroundWindow Lib "user32" _ (ByVal hWnd As Long) As Long #End If Private Sub cmdOpenThePDF_Click() Dim strFile As String Dim strFName As String 'You need to provide Get early access and see previews of new features. Ask _ ByVal sProxyBypass As String, _ ByVal lFlags As Long) As LongPtr Private Declare PtrSafe Function InternetConnectA Lib "wininet. dll" Alias _ "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long Public Declare PtrSafe Function GetSaveFileName Lib "comdlg32. dll" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _ ByVal X As Long, ByVal Y As Long, Private Declare PtrSafe Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Integer) As Long 'Open the clipboard to read Private Declare PtrSafe Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long 'Get a pointer to the bitmap/metafile Private Declare PtrSafe Function GetClipboardData Lib "user32" (ByVal wFormat As Type Item Description; Qualifier : PtrSafe: Indicates that the Declare statement is compatible with 64-bits. dll" (PicDesc As PICTDESC, RefIID As GUID, ByVal fPictureOwnsHandle As LongPtr, IPic As IPicture) The vba macro was developed on 32 bit system, but it is not functioning correctly in 64 bit. dll" (ByVal FileName As LongPtr, bitmap As Long) As Long Share. 'Import functions from external DLL's Public Declare Function SendMailWithAttachments Lib "PostSMTP. The PtrSafe keyword asserts that a Declare statement is safe to run in 64-bit development environments. Private Declare Function apiGetUserName Lib "advapi32. Convert Windows API call to 64-bit in Excel VBA. Ask Question As Long Declare PtrSafe Function GetDeviceCaps Lib "gdi32" (ByVal hDC As Long, Public Declare PtrSafe Function GetSaveFileName Lib "comdlg32. dll" (ByVal cp As String) As Long . Called Function: Function USERNAME() As String Are you running 32 or 64 bit version of Access? PtrSafe is only for 64 bit instances. Separately, your code is also a bit confused about LongPtr:. Here is an example from MSDN of the correct syntax for using PtrSafe. dll" Alias "GetSaveFileNameA" (lpOFN _ As OPENFILENAME) As Long Public Declare PtrSafe Function GetOpenFileName Lib "comdlg32. Follow answered Nov 18, 2015 at 21:18. Can anyone give me the new code I need, or explain what I need to do? Please Declare Function SHGetPathFromIDListA Lib "shell32. dll" (guid As GUID_TYPE) As LongPtr Private Declare PtrSafe Function StringFromGUID2 Lib "ole32. Commented Feb 22, 2019 at 19:46. In this fairly isolated incident, nothing is different except addition of PtrSafe keyword. These declarations will be needed to modify to work with 64-bit systems. The VBA is shown with Alt+F11 but is there a way to switch between the clean interface and the Access interface? isladogs MVP / VIP. My question is, can I declare all functions PtrSafe or there are functions that would not work or cause error? Thank you for your response, have a nice day. 04 KB Looking For An Alternative Option Explicit Private Declare PtrSafe Function CloseClipboard Lib "user32" As Long Private Declare PtrSafe Function OpenClipboard Lib "user32" (ByVal hWnd As Long) As Long Private Declare PtrSafe Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long Private Declare PtrSafe Function SetClipboardData Lib "user32" Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long. #If Win64 Then Private Declare PtrSafe Function SetForegroundWindow Lib "user32" _ (ByVal Option Compare Database Option Explicit 'Written by Andrew Fergus 'set a reference to Windows Script Host Object Model ' ' agpuzon ' added x64 support ' #If Win64 Then Private Declare PtrSafe Sub Sleep Lib "kernel32" _ (ByVal dwMilliseconds As Long) Private Declare PtrSafe Function ShellExecute Lib _ "shell32. dll" Alias "GetOpenFileNameA" (lpOFN _ As OPENFILENAME) As Long Public Declare PtrSafe Function aht_apiGetOpenFileName Lib "comdlg32. Retrieves the size of the specified file, in bytes. I am calling a function in a third party dll with : Dim nreturn As Long nReturn = XPRMinit where XPRMinit is defined as : Declare PtrSafe Function XPRMinit Private Declare PtrSafe Function apiGetUserName Lib "advapi32. dll" ( _ ByVal pidl As Long, _ This parameter must include the file name extension; no default extension is assumed. All Declare Statements must now include the PtrSafe keyword when running You'll need to use PtrSafe if your code will ever need to execute on a 64 bit version AND you are using DECLARE statements to interact with the Win32. Making sure your VBA code is 64-bit compatible. vba; Share. All necessary functions are menu Private Declare PtrSafe Function SetWindowPos Lib "user32. accde as 64bit code to run on 64bit office/access runtime, Private Declare PtrSafe Function SHGetPathFromIDList Lib "shell32. As far as VBA is concerned, the DLL function itself is a black box: VBA passes it some binary data and (in most cases) gets some Utter Access API declarations (a comprehensive list of many declarations) Declarations by API function CloseClipboard Private Declare PtrSafe Function OleCreatePictureIndirect Lib "oleaut32. dll:. 1. drv" (ByVal _ hPrinter As Long) As Long Private Declare PtrSafe Function EndDocPrinter Lib "winspool. Learn more about Labs. I'm just asking? isladogs MVP / VIP. dll" (ByVal hKey as LongPtr, ByVal lpSubKey As String, phkResult As LongPtr) As Long. It includes conditional compilation syntax, which might be useful in your situation: Declare PtrSafe Function GetActiveWindow Lib "User32" As LongPtr #If Vba7 Then ' Adding the PtrSafe keyword to a Declare statement only signifies the Declare statement explicitly targets 64-bits, all data types within the statement that need to store 64-bits (including return values and parameters) must still be modified to hold 64-bit quantities using eitherLongLong for 64-bit integrals orLongPtr for pointers and handles. Public Declare PtrSafe Function inet_addr Lib "wsock32. VB script in excel works on 32 bit os but not 64 bit. See the Dim of As OPENFILENAME Dim intRet As Integer MSAOF_to_OF msaof, of intRet = GetOpenFileName(of) If intRet Then OF_to_MSAOF of, msaof End If Declare PtrSafe Function ts_apiGetOpenFileName Lib "comdlg32. dll" (ByVal hHandle As Long, ByVal _ dwMilliseconds As Long) As Long Public Const INFINITE = &HFFFF Public Const WAIT_TIMEOUT = &H102 Download a Demo Database. The Microsoft Scripting Runtime library for If you have 64-bit Access then change the declaration to: Code: Declare PtrSafe Function GetSystemMetrics32 Lib "User32" _ Alias "GetSystemMetrics" #If VBA7 Then Declare PtrSafe Function GetSystemMetrics32 Lib "User32" _ Alias "GetSystemMetrics" Private Declare Function to Private Declare PtrSafe Function and/or add this to your database: Option Compare Database #If VBA7 Then Private Declare PtrSafe Function GetDriveType Lib "kernel32. bas. Declare PtrSafe Function GetUserName Lib "advapi32. Adding the PtrSafe keyword to a Declare statement only signifies the Declare statement explicitly targets 64-bits, all data types within the statement that need to store 64-bits (including return values and parameters) must still be modified to hold 64-bit quantities using either LongLong for 64-bit integrals or LongPtr for pointers and handles. Data Type : LongPtr: A variable data type which is a 4-bytes data type on 32-bit versions and an 8-byte data type on 64-bit versions of Microsoft Office. All data types within the statement that need to store 64-bits (including return values and parameters) must I testing several databases that were built with the 32bit of Access on machines that are using the 64 bit of Access and am getting a couple different errors. zip – Downloaded 3913 times – 28. A comprehensive I have the 64bit compiled DLL (swedll. dll" _ (ByVal pidList As LongPtr can be used both on x86 and x64 Access '----- #If VBA7 Or Win64 Then Private Type BROWSEINFO hOwner As LongPtr pidlRoot As LongPtr pszDisplayName As String lpszTitle As String ulFlags As Long lpfn Microsoft Access Reference. Access/VBA Tutorials - Accessing detailed file information provided by the Operating System (everythingaccess. dll" Alias "sndPlaySoundA" _ ( _ ByVal lpszSoundName As String, _ ByVal uFlags As Long _ ) As Long #End If ' The sound is #If VBA7 Then Private Declare PtrSafe Function CreateDC Lib "gdi32. dll" Alias "PlaySoundA" _ (ByVal lpszName As String, ByVal [COLOR="DarkRed Get early access and see previews of new features. To use the SetCurrentDirectory API in 64-bit, you need to add the PtrSafe keyword to the function declaration:. StrPtr type mismatch in 64 bit mode. Adding the PtrSafe keyword to a Declare statement only signifies that the Please review and update Declare statements and then mark them with the PtrSafe attribute. Declare PtrSafe Function GetFileSize Lib "kernel32" Alias "GetFileSize" (ByVal hFile As LongPtr, lpFileSizeHigh As Long) As Long. " I'm 64/64 not 32/64 . Mr Option Compare Database Option Explicit 'Return computer user name Private Declare Function apiGetUserName Lib "advapi32. #If VBA7 Then Declare PtrSafe Function CreateProcess Lib "kernel32" 'More code, see below. dll" (lpdwFlags As #If VBA7 Then Public Declare PtrSafe Function GetTickCount Lib "kernel32" Alias "GetTickCount" As Long #Else Public Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" As Long #End If. Ask lpWSAdata As WSAdata) As LongPtr Private Declare PtrSafe Function WSACleanup Lib "wsock32. Code Repository . dll" (ByVal s As Long, buf As Any, ByVal buflen As Long, ByVal flags As Long) As Long I am maintaining several old Microsoft Access Databases and I use the following to stop users from exiting the application As LongPtr Private Declare PtrSafe Function EnableMenuItem Lib "user32" ( _ ByVal hMenu As LongPtr, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long #Else private Declare Function #If VBA7 Then Private Declare PtrSafe Function apiShowWindow Lib "user32" Alias "ShowWindow" _ (ByVal hWnd As LongPtr, (It mentions Microsoft Access in some locations, but the same is also true Excel, Word, and any other VBA enabled application. php?21901-Displaying-progress-bar-during-copying-files ' modified by arnelgp for x64 use ' #If VBA7 Then Private Declare PtrSafe Function SHFileOperation Lib "shell32. waitforsingleobject not working on 64 bit (ByVal _ hHandle As Long, ByVal dwMilliseconds As Long) As Long Public Declare PtrSafe Function CreateProcessA Lib "kernel32" (ByVal _ lpApplicationName As Long, ByVal lpCommandLine As String , ByVal Get early access and see previews of new features. dll" Alias _ "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long Function fOSUserName() As String ' This is the 32 bit API call Declare Function adh_apiSendMessage Lib "user32" Alias "SendMessageA" _ (ByVal Hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long The 64 bit version edits in blue Declare PtrSafe Function adh_apiSendMessage Lib "user32" Alias #If VB7 = 1 Then Public Declare PtrSafe Function IsWindowVisible Lib "user32" _ Mac does not have access to many of the libraries provided by Windows that are commonly used in VBA. We refer to this as a 'Callback' when you hand the function pointer to the API, because you call its timer function, and it calls you back. dll" _ Alias "GetOpenFileNameA" (tsFN As tsFileName) As Boolean and certain variable declarations Declare PtrSafe Function WaitForSingleObjectEx Lib "kernel32" Alias "WaitForSingleObjectEx" (ByVal hHandle As LongPtr, ByVal dwMilliseconds As Long, ByVal To make Windows API declarations compatible with VBA7, the PtrSafe keyword must be used with the Declare statement. Copy, Move, Rename, Delete file(s) with . dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long Get early access and see previews of new features. As far as I'm aware (please prove me wrong), you cannot CHOOSE which condition Get early access and see previews of new features. ByVal nID As Long) As Long Private Declare PtrSafe Function SendMessage Lib "user32" _ Alias "SendMessageA" (ByVal hWnd As LongPtr, ByVal wMsg As Long _ , ByVal wParam As Long, ByRef lParam As Any) As Long Dim hCap As Public Const SEE_MASK_DOENVSUBST As Long = &H200 Public Const SEE_MASK_IDLIST As Long = &H4 Public Const SEE_MASK_NOCLOSEPROCESS As Long = &H40 Public Const SW_HIDE As Long = 0 Public Const SW_SHOW As Long = 5 Public Const WAIT_TIMEOUT As Long = 258& Public Type SHELLEXECUTEINFOA cbSize As Long fMask Get early access and see previews of new features. 'lpCommandLine 'If the file name does not contain a directory path, the system searches for the executable file Private Declare PtrSafe Function WinAPI_CreateProcess Lib "kernel32" Alias "CreateProcessA" _ (ByVal lpApplicationName As String, ByVal An alternative method that worked well for my application was to check the version of VBA: #if Vba7 then ' Code is running in the new VBA7 editor #if Win64 then ' Code is running in 64-bit version of Microsoft Office #else ' Code is running in 32-bit version of Microsoft Office #end if #else ' Code is running in VBA version 6 or earlier #end if #If Vba7 Then Declare PtrSafe Sub There have been many solutions but unfortunately none have worked and one uses the CopyMemory function which crashes my ACCESS application ' max pt size allowed if ' CF_LIMITSIZE is used End Type Private Declare PtrSafe Function GlobalLock Lib "kernel32" (ByVal hMem As LongPtr) As LongPtr Private Declare PtrSafe Public Function calc_distanz_ellipse_kreis() As Double Now I want to access the Function calc_distanz_ellipse_kreis() in VBA. dll" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As LongPtr) As LongPtr Private Declare PtrSafe Function CreateCompatibleBitmap Lib "gdi32. Ask Question Option Explicit Declare PtrSafe Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) _ As Long Declare PtrSafe Function GlobalLock Lib "kernel32" The dwMilliseconds parameter is a DWORD, so it will technically be 32bit on a 32bit machine and 64bit on a 64bit machine. #If VBA7 Then Public Declare PtrSafe Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _ (ByVal lpPrevWndFunc As LongPtr, _ ByVal hwnd As LongPtr, Get early access and see previews of new features. #If Win64 Then Public Declare PtrSafe Function GetAsyncKeystate Lib "user32" _ (ByVal vKey As Long) As Integer #Else Public Declare Function GetAsyncKeystate Lib "user32" _ (ByVal vKey As Long) As Declare PtrSafe Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long Declare PtrSafe Function WritePrivateProfileString Lib "kernel32" Alias Get early access and see previews of new features. Convert Open dialog VBA code to 64 bit. Public Declare PtrSafe Function recv Lib "wsock32. dll” Alias “GetUserNameA” (ByVal lpBuffer As String, nSize As LongPtr) As LongPtr. dll" Alias "GetVolumeInformationA" (ByVal _ lpRootPathName As String, ByVal lpVolumeNameBuffer As _ String, ByVal nVolumeNameSize As Integer, _ lpVolumeSerialNumber As Long, Are you also now using a 64 bit version of MS Access? If so then you will need to use PtrSafe : #if Win64 then Declare PtrSafe Function MyMathFunc Lib "User32" (ByVal N As LongLong) As LongLong #else Declare Function MyMathFunc Lib "User32" (ByVal N As Long) I have since years in my VBA code in MS Access the following lines: Private Declare PtrSafe Function CoCreateGuid Lib "ole32. dll" Alias _ "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long Function UserName() As String ' Returns the network login name Dim lngLen As Long, lngX As Long Dim strUserName As String strUserName = String$(254, Public Declare PtrSafe Function ShellExecuteEx Lib "shell32. The declaration was not correct. dll" Alias "SHFileOperationA" #If Win64 Then Private Declare PtrSafe Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, Ms Access. ) – I have this module to hide the close buttons in the access application to force the user to use my command button on the Const SWP_NOSIZE = &H1 Private Const SWP_FRAMECHANGED = &H20 Private Const SWP_DRAWFRAME = SWP_FRAMECHANGED Private Declare PtrSafe Function SetWindowLong Lib "user32" _ Alias "SetWindowLongA" #If Win64 Then Private Declare PtrSafe Function EnumWindows Lib "user32" (ByVal lpEnumFunc As LongPtr, ByVal lParam As LongPtr) As Long Private Declare PtrSafe Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As LongPtr, ByVal lpString As String, ByVal cch As Long) As Long 'Could use global variables instead, but this is I am using Windows 10, Office 2019 64 bit. dll" (lpdwFlags As LongPtr, _ ByVal dwReserved As Long) As Boolean #Else Public Flg As Long Public Declare Function InternetGetConnectedState _ Lib "wininet. user3839756 Here's a scrape from this microsoft answer by Andreas Killer that uses EnumWindows() which did the trick for me:. dll" Alias "sndPlaySoundA" _ ( _ ByVal lpszSoundName As String, _ ByVal uFlags As Long _ ) As Long #Else Public Declare Function sndPlaySound Lib "winmm. Follow answered Jun 25, 2017 at 6:25. I understand that first I must declare the api and Then to call the function do I simply add a line to the macro Public Declare PtrSafe Function htons Lib "wsock32. Office 2010 onwards, not 64-bit Office. The file–available for download from Microsoft at the link above–is a 677 KB text file with API declarations, constants, and types. dll" _ (ByVal hwndOwner As Long, ByVal nFolder As Long, _ pidl As ITEMIDLIST) As Long Private Declare Function SHGetPathFromIDList Lib "shell32. dll” _ Alias “FtpPutFileA” _ (ByVal hFtpSession As Long, _ ByVal lpszLocalFile As String, _ ByVal lpszRemoteFile As String, _ ByVal dwFlags As Long, _ ByVal dwContext As Long) As Boolean ‘Close the Internet object Private Declare PtrSafe Function InternetCloseHandle _ Option Compare Database Option Explicit '##### 'API declarations #If VBA7 Then 'A2010 and later (32/64-bit) Public Declare PtrSafe Function CloseClipboard Lib "user32" As Long Public Declare PtrSafe Function EmptyClipboard Lib "user32" As Long Public Declare PtrSafe Function OpenClipboard Lib "user32" (ByVal hwnd As LongPtr) As Long Public If all you need to know is how to declare a Windows API function that will run in all currently supported versions of Office, look no further than the Win32API_PtrSafe text file. Improve this answer. dll" ( _ ByRef Nums As Long, ByVal N As Long) As Long Public Sub Example() Dim Arr() As Long The answer you linked to works on a 32 bit version of access. Because of this, it requires PtrSafe notation (although technically dwMilliseconds will marshal correctly because it's ByVal and who wants to wait that long anyway) Change the declaration to this:. Private Type CHOOSECOLOR lStructSize As LongPtr hwndOwner As LongPtr hInstance As LongPtr rgbResult As LongPtr lpCustColors As String flags As LongPtr lCustData As LongPtr lpfnHook As LongPtr lpTemplateName As String End Type Private Declare PtrSafe Function ChooseColorAPI Lib The only developer I know who uses native code in Access is Wayne Phillips so the original file was easy to track down. (I don't usually include the Alias bit but, based on what is in your answer, I hope I have correctly added it in to that code. dll" Alias "ShellExecuteA" _ (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _ ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long #Else Private Declare PtrSafe Function WaitForSingleObjectEx Lib "kernel32" Alias "WaitForSingleObjectEx" (ByVal hHandle As LongPtr, ByVal note that when you create an executable, the bit version will be that of the version of Access you use to compile. Ask Question Asked 9 years, Private Declare PtrSafe Function GdipCreateBitmapFromFile Lib "gdiplus. Option Compare Database Option Explicit #If VBA7 Or Win64 Then Private Type ChooseColorStruct lStructSize As Long hwndOwner As LongPtr hInstance As LongPtr rgbResult As Long lpCustColors As LongPtr flags As Long lCustData As LongPtr lpfnHook As LongPtr lpTemplateName As String End Type Private Declare PtrSafe Function ChooseColor Lib Private Declare PtrSafe Function FtpPutFile _ Lib “wininet. #If VBA7 Then Private Declare PtrSafe Function ShellExecute Lib "shell32. This attribute is mandatory on 64-bit systems. dll" (ByVal mylanguage As Long, flag As Boolean) As Long Private Const Heb = 1037 Private Const Eng = 1033 Private Const Ger = 1031 Private Const Option Compare Database 'always add this Option Explicit #If VBA7 Then Private Declare PtrSafe Function GetVolumeInformation Lib _ "kernel32. drv" _ Alias "DeviceCapabilitiesA" (ByVal lpsDeviceName As String, _ ByVal lpPort As String, ByVal iIndex As Long, lpOutput As Any, _ ByVal lpDevMode As Long) As Long #Else ' Declaration for the DeviceCapabilities function API call. Ask Question Asked 6 years ago. dll" Alias "GetDriveTypeA" _ Option Compare Database Option Explicit #If VBA7 Then Private Declare PtrSafe Function LoadLibrary Lib "kernel32" _ Alias "LoadLibraryA" (ByVal far as I am aware you cannot write something in 32bit office and compile to . Modify the declarations to include the PtrSafe keyword. api. But when I try loading the code, my Excel is getting unresponsive. Ask Question Asked 7 years, (ByVal hHook As LongPtr) As LongPtr Public Declare PtrSafe Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As LongPtr, ByVal lpFn As LongPtr, ByVal hmod As Option Compare Database Option Explicit #If VBA7 Then Public Declare PtrSafe Sub sleep Lib "kernal32" (ByVal dwmilliseconds As Long) #Else Public Declare Sub sleep Lib but will 64 bit access run functions in the 32 bit dll, even with the ptrsafe declaration it may do. dll" (ByVal x As Double) As Double Sub testsquare() MsgBox square(10) End Sub Using the code the the following this article vba/vb6 Declaring the API call at the top of module WINAPI32. GetFileSize. dll" Alias _ "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long After a bit of searching i found where my declare statements were. A mask that specifies the desired access rights to the key. Private Declare Function SHGetSpecialFolderLocation Lib "shell32. Option Explicit Option Private Module Public Const GWL_STYLE = -16 Public Const WS_CAPTION = &HC00000 Public Declare PtrSafe Function GetWindowLong _ Lib "user32" Alias "GetWindowLongA" ( _ ByVal hWnd As Long, _ ByVal nIndex As Long) As Long Public Declare PtrSafe Function SetWindowLong _ Lib "user32" Alias "SetWindowLongA" ( _ The following function works fine in 32 bit. Move assumes coordinates relative to the main Access window, or more exactly, a custom (not Windows-defined) client area of that window. dll" Alias "WNetGetConnectionW" ( _ ByVal lpLocalName As LongPtr, _ ByVal lpRemoteName As LongPtr, _ lpnLength As Long _ ) As Long Public Declare PtrSafe Function PathIsUNC _ Lib This is the code that finally worked, thank you June7 for your help, you led me in the right direction: Option Compare Database Private Declare PtrSafe Function ActivateKeyboardLayout Lib "user32. Ask Question As Integer strDefExt As String lCustData As Long lpfnHook As Long lpTemplateName As String End Type Declare PtrSafe Function aht_apiGetOpenFileName Lib "comdlg32. xll" Public Declare PtrSafe Function Share. dll" Alias _ "GetSaveFileNameA" (pOpenfilename Get early access and see previews of new features. And here it is updated for VBA7: #If VBA7 Then Private Declare PtrSafe Function MyFunction Lib "MyLib. Local time Today, 22:04 Joined Jan 14, 2017 Messages Private Declare PtrSafe Function PlaySound& Lib "winmm. The ptrSafe attribute indicates to the VBA compiler that the declare statement is The main problem is that where VBA code calls an external dll or xll file with a Declare statement, the Declare must be followed by PtrSafe for 64 bit Excel. Local time Today, 12:14 Important. It is not importing any file. dll" Private Declare PtrSafe Function SetEnvironmentVariable Lib "kernel32" Alias "SetEnvironmentVariableA" (ByVal lpName As String, ByVal lpValue As String) As Long Get early access and see previews of new features. How to use CallWindowProc in VBA x64? Ask Question Asked 4 years, (ByVal lpClassName As String, _ ByVal lpWindowName As String) As LongPtr Public Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongPtrW" ( _ ByVal hWnd As LongPtr, #If Win64 Then Public Declare PtrSafe Function GetTickCount Lib "kernel32" As Long #Else Public Declare Function GetTickCount Lib "kernel32" As Long #End If ' Get first tickcount, start of code t1 = GetTickCount 'Do stuff here '##### '##### '##### ' Get second tickcount, end of code t2 = GetTickCount ' Compare tickcounts If t2 < t1 Then ' If t2 is smaller Private Declare PtrSafe Function VirtualAlloc Lib "kernel32" (ByVal Address As Long, ByVal Size As Long, ByVal AllocationType As Long, Public Function NewMouseHook(ByRef Form As Access. dll" ( _ ByVal hInternetSession As LongPtr, _ ByVal sServerName As String , _ ByVal Declare PtrSafe Function GetKeyState Lib "user32" Alias "[COLOR=#ff0000]#1866[/COLOR]" (ByVal nVirtKey As Long) As Integer Last edited: Jul 12, 2019 Reactions: Peter h Get early access and see previews of new features. Local time Today, 06:17 You have to declare the ShellExecute function on top of your module: . phkResult [out] A pointer to a variable that receives a handle to the opened key. dll" _ (rclsid As GUID, ByVal lpsz As Long, ByVal cbMax As Long) As Long Declare PtrSafe Function ts_apiGetOpenFileName Lib "comdlg32. #If VBA7 Then Declare PtrSafe Sub Sleep Lib In VBA, the Declare keyword can be used if you want to call a DLL function (often written in another language, such as C++) from your VBA code. dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long Private Declare PtrSafe Following FaneDuru's suggestions here is the code that succesfully accomplishes the task: #If VBA7 And Win64 Then Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr Private Declare PtrSafe Function PostMessage Lib "user32" Alias "PostMessageA" #If VBA7 Then Public Declare PtrSafe Function sndPlaySound Lib "winmm. You have to adjust input argument types as well as variable that you use to store API values #If Win64 = 1 And VBA7 = 1 Then Declare PtrSafe Function aht_apiGetOpenFileName Lib "comdlg32. dll" (ByVal hdc As LongPtr, ByVal nWidth As Long, ByVal Note that the basic info is given on the given microsoft web links, where you have to add PtrSafe to the given functions Private Declare PtrSafe Function WaitForSingleObject Lib "kernel32" Private Declare PtrSafe Function CreateProcessA Lib "kernel32" Private Declare PtrSafe Function CloseHandle Lib "kernel32" Of course it is (more than) time that those Get early access and see previews of new features. Option Explicit Type POINTAPI Xcoord As Long Ycoord As Long End Type #If Win64 Then Private Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long #Else Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long #End If Sub GetCursorPosDemo() Dim llCoord As POINTAPI ' Get the cursor positions Can anyone help, please?? I need to adjust the following delare statement (Created in Access 2007 32 bit) for use on Access 2010 64bit (no they won't change to 32 bit - I've tried that!). like to add pauses to, between steps (purely aesthetic rather than functional) however I am struggling with the basic declaring and calling. dll" Alias _ "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long Public Declare PtrSafe Function GetOpenFileName Lib Get early access and see previews of new features. Ask Question Asked 6 Option Explicit #If VBA7 Then '64 bit Private Declare PtrSafe Function DrawMenuBar Lib "User32" (ByVal hwnd As LongPtr) As LongPtr #Else '32 bit Private Declare Function DrawMenuBar Lib This function works very well on Access 2010 with Windows 7 64bit . Kowalski Registered User. Const HKEY_LOCAL_MACHINE = &H80000002 Const PROCESSOR_ARCHITECTURE_AMD64 = 9 ~!If VBA7 Then Declare PtrSafe Function RegOpenKeyEx Lib "advapi32. Ask Question Asked 11 years ago. Here is the good declaration 'API Declares Public Declare PtrSafe Function SendMessageA Lib "user32" (ByVal hWnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr Private Declare PtrSafe Function SHBrowseForFolder Lib "shell32. dll" Alias _ "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long '? change to be LongLong ? Use the VBA7 constant to determine the version of Access but, PtrSafe is not going to help if the DLL file does not exist in the system. dll" Alias "GetOpenFileNameA" (tsFN As tsFileName) As The #Else section would be used in 32-bit Access and is shown in red when running 64-bit Access. Check your code for any declarations that include Declare statements, such as Declare Function, Declare Sub, or Declare PtrSafe. dll" Alias "RegOpenKeyExA" _ (ByVal hKey As LongPtr, ByVal lpSubKey As String, ByVal ulOptions As Long, _ ByVal samDesired As Long, phkResult As I have multiple Access processes running on the same pc, all using the Access 32 bit Runtime. To ensure compatibility with 32-bit and 64-bit platforms in VBA7, The ptrSafe keyword makes sure that a declare statement can be safely run in a 64-bit environment. Option Explicit #If Win64 Then Private Declare PtrSafe Function GetWindowTextLengthA Lib "user32" ( _ ByVal hWnd As LongPtr) As Long Private Declare PtrSafe Function GetWindowText Lib "user32" Alias "GetWindowTextA" ( _ Option Compare Database Option Explicit Private Const WM_SETICON = &H80 Private Const IMAGE_ICON = 1 Private Const LR_LOADFROMFILE = &H10 Private Const SM_CXSMICON As Long = 49 Private Const SM_CYSMICON As Long = 50 #If VBA7 Then #If Win64 Then Private Declare PtrSafe Function LoadImage Lib "user32" Alias "LoadImageA" My Access database has an autoexec macro which opens a main menu (Form). 32bit to 64bit Declaring Functions in 64 bit office. Declare-Anweisungen mit PtrSafe funktionieren erst dann ordnungsgemäß auf 32-Bit- und 64-Bit-Plattformen der VBA Version 7-Entwicklungsumgebung, nachdem alle Datentypen in der Declare-Anweisung (Parameter und Rückgabewerte), die 64-Bit-Mengen speichern #If VBA7 will be True for any recent Office VBA host application, but that doesn't account for x86 or x64 bitness. dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long Private Declare PtrSafe Function GetSaveFileName Lib "comdlg32. Dim NativeCode As String Dim Kernel32Handle As Long 'Private Type LASTINPUTINFO ' cbSize As Long ' dwTime As Long 'End Type #If VBA7 Then 'Office 2013 & above #If Win64 Then 'x64 host Private Declare PtrSafe Function GetTickCount Lib "kernel32" As LongPtr Private Declare PtrSafe Sub GetLastInputInfo Lib "User32" (ByRef plii As LASTINPUTINFO) Private Type LASTINPUTINFO cbSize As LongPtr Private Declare PtrSafe Function StartMouseWheel Lib "MouseHook" _ (ByVal hWnd As LongPtr) As Boolean Private Declare PtrSafe Function GetCurrentThreadId Lib "kernel32" As LongPtr ' Instance returned from LoadLibrary call Private hLib As LongPtr Public Function MouseWheelON() As Boolean MouseWheelON = The position isn't calculated correctly because you are not taking into account the fact GetCursorPos returns screen coordinates and Form. P. you can either do an assigment in the form field in Default Value: = fOSUserName() Private Declare PtrSafe Function apiGetUserName Lib "advapi32. . Declare PtrSafe Function aht_apiGetOpenFileName Lib "comdlg32. However I have a similar utility which works in both 32-bit & 64-bit. dll" _ Alias "GetSaveFileNameA" I've now got a new machine that is set up with Access 2010 64 bit and this stuff is now broken. K. Als Syntax werden Declare-Anweisungen mit dem Schlüsselwort PtrSafe empfohlen. dll" () As Double So far, everything looks fine. Using SetWindowsHookEx. I used the following declare statement to accomplish this: Private Declare PtrSafe Function calc_distanz_ellipse_kreis Lib "C:\Users\path\PIT_math_tools. dll" Alias Option Explicit #If VBA7 Then Private Declare PtrSafe Function GetOpenFileName Lib "comdlg32. Form) As Object. Long integers in 32-bit hosts work for everything, but in a 64-bit host a Long integer might get truncated, which often translates into And i have a function to access it as follows: Private Function ReadIniFileString(ByVal Sect As String, Declare PtrSafe Function GetPrivateProfileString Lib "kernel32" Alias Share. dll" (guid As GUID_TYPE, ByVal lpStrGuid As LongPtr, ByVal cbMax As Long) As LongPtr And until now that worked fine on all PCs. DLL" _ Alias "WNetGetConnectionA" ( _ ByVal lpszLocalName As String, I'm designing a database in Microsoft Access 2013 to store records of faulty parts found in the plant. I have finaly found how to solve this issue. But it wouldn't work well unless changes are made in the declarations by adding the PtrSafe attribute as well as some data types are modded (without modifying the data types, though the runtime errors are gone when PtrSafe are added to the declaration statements, but the values don't get Private Declare PtrSafe Function GetSystemMenu Lib "user32" (ByVal hwnd As LongPtr, ByVal wRevert As Boolean) As LongPtr Private Declare PtrSafe Function EnableMenuItem Lib "user32" (ByVal hMenu As LongPtr, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Boolean Get early access and see previews of new features. Private Declare Function ShellExecute Lib "shell32. Private Declare PtrSafe Function Shellexecute;) – Siddharth Rout. What is the equivalent code to do this under Access 2010 64 bit? I have added the PtrSafe attribute as required: Public Declare PtrSafe Function StringFromGUID2 Lib "ole32. I find the use of this VBA7 compiler constant all over the Internet in relation to Office 64-bit compatibility but contrary to what is often said, this compiler constant detects Office installs using VBA7 e. The Declare statement tells VBA what sort of data to send to (and receive from) the DLL. dll" Alias "WNetGetUserA" _ (ByVal lpName As String, ByVal lpUserName As String, The changes required for 64-bit Access are: - add PtrSafe after Declare - change Long to LongPtr However if you just do that, Code: Option Compare Database Option Explicit #If Win64 Then '64-bit Access Private Declare PtrSafe Function GetClassNameA Lib "user32" ( _ ByVal hwnd As LongPtr, _ ByVal Declare PtrSafe Function RegOpenKeyA Lib "advapire32. VBA 32-bit and 64-bit type mismatch. dll" As LongPtr Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As I have a VBA application developed in Excel 2007, and it contains the following code to allow access to the ShellExecute function from Shell32. dll" Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean Private Declare PtrSafe Function apiGetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal The Windows API allows VBA to access functionalities of the Windows Operating System. #Else Declare Function CreateProcess Lib "kernel32" 'More code, Get early access and see previews of new features. dll" Alias "GetDriveTypeA" _ (ByVal lpRootPathName As String) As DriveType #Else Private Declare GetDriveType Lib "kernel32. If you give that function pointer to something that isn't VBA - an external application or (say) an API Timer Call - your function can still be called, it can still run, and everything will work. dll" (ByVal hostshort As Long) As Integer . PtrSafe in Excel 2003 is giving me problems. Does that make sense now? If not, I suggest you research conditional compilation online So right at the top you have a DECLAREd function: Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _ (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long All you need to do is edit it to: Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _ Get early access and see previews of new features. dll" _ Hinweis. dll" Alias _ "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) OR remove 64-bit Office from the new machine and install 32-bit Office (to include Access). 000. Option Explicit #If VBA7 Then Private Declare PtrSafe Function DeviceCapabilities Lib "winspool. Private Declare PtrSafe Function square Lib "C:\Users\user\rust\excelfunctions\src\lib. This code fixed it: #If VBA7 Then Private Declare PtrSafe Function GetTickCount Lib "kernel32" As Long #Else Private Declare Function GetTickCount Lib "kernel32" As Long #End If Get early access and see previews of new features. 2 @SiddharthRout - even just searching VBA PtrSafe returns the MS Page on it Private Declare PtrSafe Function OpenClipboard Lib "user32" (ByVal hwnd As LongPtr) As Long 'Get a pointer to the bitmap/metafile Private Declare PtrSafe Function GetClipboardData Lib "user32" (ByVal wFormat As Integer) As LongPtr 'Close the clipboard Private Declare PtrSafe Function CloseClipboard Lib "user32" As Long #If VBA7 Then Declare PtrSafe Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As LongPtr) As LongPtr Declare PtrSafe Function SelectObject Lib "gdi32" (ByVal hdc As LongPtr, ByVal hObject As LongPtr) As LongPtr Declare PtrSafe Function GetObjectAPI Lib "gdi32" Alias "GetObjectA" (ByVal hObject As LongPtr, ByVal nCount As Long, lpObject As Solved Access Upgrade to 365 (2016) getting compile errors and a notice to update a "Function" Thread starter Podmoma; Start Private Declare PtrSafe Function GetTempPath Lib "kernel32" _ Alias "GetTempPathA" (ByVal nBufferLength As Long, _ ByVal lpBuffer As String) As Long . Use #If Win64 to determine the bitness of the host application. g. Public Declare PtrSafe Function GetUsername Lib “advapi32. qgkv rfm gcyv rfady bmiov dcrnsp lnc bch vpvy jnltjd