API's in VBA for Excel
|
613-749-4695 (Peter) |
Tips and Ideas on Excel |
Tips and Ideas on Macros |
VBA Chapter 22 of 24: API's in VBA for ExcelAPI stands for Application Programming Interface and consists of a collection of functions that provide programmatic access to the features of the operating system (Windows). When you use API's within VBA for Excel not only do you control Excel but all the other parts of Windows. Here is how it works if you want to copy a file from a directory to the other. You must first declare the API function that you want to use in your code (Private Declare....CopyFile...). Then you call it from you procedure (Sub proCopyFile...). Notice that you must ALWAYS use a variable to receive the result of an API function (varCopy = CopyFile("C:\amy.xls" , "E:\SCI\amy.xls" , 1)) Option Explicit Private
Declare Function CopyFile Lib "kernel32.dll" Alias "CopyFileA"
_ Sub proCopyFile() Dim varCopy As Long varCopy = CopyFile("C:\amy.xls" , "E:\SCI\amy.xls" , 1) If varcopy< > 0 Then MsgBox "Copy succeeded." End Sub |
Next Chapter: Userforms in VBA for Excel |
VBA Table of Contents |
|
|
613-749-4695 (Peter) |
Tips and Ideas on Excel |
Tips and Ideas on Macros |
API's in VBA for Excel