![api vba api vba](https://i.stack.imgur.com/o2Aju.png)
![api vba api vba](https://i.ytimg.com/vi/S7cUToPQkl4/maxresdefault.jpg)
Windows API procedures that do return a value should be declared in VBA as Functions. Windows API procedures that do not return a value should be declared in VBA as a Subs. Result = WinAPIURLDownloadToFile(FileURL, DownloadPath) To ensure compatibility with 32-bit and 64-bit platforms in VBA7, use the LongPtr type for all pointers and handles.ÄownloadPath = Environ$("USERPROFILE") & "\Desktop\Example_WinAPI_PtrSafe.txt" To make Windows API declarations compatible with VBA7, the PtrSafe keyword must be used with the Declare statement.
#API VBA CODE#
To declare a procedure using an alias, specify the original name of the procedure as declared within the code resource using the Alias clause. Specify the location of the procedure using the Lib keyword. To declare Windows API procedures use the Declare statement. Because VBA7 requires the PtrSafe keyword to be used in declarations and the LongLong and LongPtr types were added, there are two versions of the VBA Windows API declarations provided by Microsoft. Microsoft has provided the VBA declarations for Windows API procedures to be used freely.
![api vba api vba](https://software-solutions-online.com/wp-content/uploads/2014/07/hyperlinks11.png)
Windows API procedures are declared in VBA and then called directly in VBA code or through a wrapper procedure written in VBA which manages usage of the Windows API procedure. The Windows API allows VBA to access functionalities of the Windows Operating System.