Windows API Calls.

N

NateBuckley

Hello, I'm just wondering if someone could explain why they would make calls
to Windows API? What this actually means, and what extra functionality this
gives VBA? I've seen a few good examples which include things from win32 api,
but I'm a little lost.

Thank you for any answers in advance.
 
B

Bob Phillips

Why? Because they can do things that can't be done using native VBA, such as
resizing a userform in VBA. Basically, you are tapping directly into
operating system functions, extending the functionality, and often
increasing the performance.

I am sure that the question has more depth than that simple answer, but I am
not sure what.

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
N

NateBuckley

Thanks for the speedy reply,

That helped, I just simply had no idea about these Windows Api Calls, Quite
Intriguing, as I've never used them before.

I shall go forth and attempt to learn the basics.

Thank you.
 
C

Chip Pearson

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top