I would add to the discussion that API calls are completely unforgiving. If
you provide an invalid value for a parameter, you are quite likely to
immediately crash the entire application (though probably not Windows
itself). SAVE YOUR WORK before calling code containing APIs unless you are
sure you have the correct data types and values. Pay attention to the ByVal
and ByRef modifiers in the API declaration -- they matter.
Note also that errors and return values that indicate error conditions are
completely independent and separate from any error handling you may have in
place using VB/VBA's On Error statements. On Error has no effect relative
to API calls. If, according the the API documentation, a function sets the
last error and that you can get further information using GetLastError, you
should use Err.LastDllError to get the error value generated by the API. The
error numbers reported by Err.LastDllError are different from the error
numbers used in Err.Number. Thus, the Err.Description property cannot be
used to get the text description of an error. If you need to get the text
description of an API-caused error, you need to use the FormatMessage API
function. I have code that wraps up FormatMessage in VB/VBA-friendly code at
http://www.cpearson.com/Excel/FormatMessage.aspx.
--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)