Microsoft Office Tutorials and References
In Depth Information
Windows API Calls
Figure 11-18: The RangeRandomize function returns the contents of a range, in random order.
Windows API Calls
VBA has the capability to use functions that are stored in Dynamic Link Libraries (DLLs). The
examples in this section use common Windows API calls to DLLs.
For simplicity, the API function declarations presented in this section work in Excel
2010 only (both the 32-bit and 64-bit versions). However, the example files on the
CD-ROM use compiler directives so they will work with previous versions of Excel.
Determining file associations
In Windows, many file types are associated with a particular application. This association makes it
possible to double-click the file to load it into its associated application.
The following function, named GetExecutable , uses a Windows API call to get the full path to
the application associated with a particular file. For example, your system has many files with a
.txt extension — one named Readme.txt is probably in your Windows directory right now.
You can use the GetExecutable function to determine the full path of the application that
opens when the file is double-clicked.
Windows API declarations must appear at the top of your VBA module.
Private Declare PtrSafe Function FindExecutableA Lib “shell32.dll” _
(ByVal lpFile As String, ByVal lpDirectory As String, _
ByVal lpResult As String) As Long
 
Search JabSto ::




Custom Search