| Start | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| API declaration and usage Declaring a DLL procedure (opens new window) to work with different VBA versions: The above declaration tells VBA how to call the function "Sleep" defined in file Kernel32.dll Win64 and Win32 are predefined constants used for conditional compilation (opens new window) Pre-defined Constants Some compilation constants are already pre-defined. Which ones exist will depend on the bitness of the office version you're running VBA in. Note that Vba7 was introduced alongside Office 2010 to support 64 bit versions of Office.
These constants refer to the Office version, not the Windows version. For example Win32 = TRUE in 32-bit Office, even if the OS is a 64-bit version of Windows. The main difference when declaring APIs is between 32 bit and 64 bit Office versions which introduced new parameter types (see Remarks section for more details) Notes:
Simple example for the Sleep API call: It is recommended to create a dedicated API module to provide easy access to the system functions from VBA wrappers -- normal VBA Subs or Functions that encapsulate the details needed for the actual system call such as parameters used in libraries, and initialization of those parameters The module can contain all declarations and dependencies:
To declare a DLL procedure, add a If the procedure returns a value, declare it as a Function: If a procedure does not return a value, declare it as a Sub:
Also of note is that **most invalid calls to the API's will crash Excel**, and possibly corrupt data files
Office 2011 for Mac The examples bellow (Windows API - Dedicated Module (1 and 2)) show an API module that includes common declarations for Win64 and Win32 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
Windows API - Dedicated Module (1 of 2) (continued in second example) |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
Windows API - Dedicated Module (2 of 2) |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
| Mac APIs Microsoft doesn't officially support APIs (opens new window) but with some research more declarations can be found online Office 2016 for Mac is sandboxed Unlike other versions of Office apps that support VBA, Office 2016 for Mac apps are sandboxed. Sandboxing restricts the apps from accessing resources outside the app container. This affects any add-ins or macros that involve file access or communication across processes. You can minimize the effects of sandboxing by using the new commands described in the following section. New VBA commands for Office 2016 for Mac The following VBA commands are new and unique to Office 2016 for Mac.
Office 2011 for Mac (opens new window) Office 2016 for Mac (opens new window) |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
Get total monitors and screen resolution |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
| FTP and Regional APIs modFTP modRegional: RemarksCommon operating environment library files (DLL's):
New arguments used for the 64 system:
Full reference of call signatures: |
Read Article
https://develop.horje.com/learn/1434/reference