通过 VBA 访问 DLL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5822438/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 13:07:41  来源:igfitidea点击:

Accessing DLLs through VBA

excelvbadll

提问by Kshitij Saxena -KJ-

How can I access the functions inside a third-party DLL from VBA (Excel)? Also, is there a way to see what all functions are available inside a DLL?

如何从 VBA (Excel) 访问第三方 DLL 中的函数?另外,有没有办法查看 DLL 中所有可用的函数?

回答by Justin

To call a function in a third-party DLL, you need to use the Declarestatement. For example:

要调用第三方 DLL 中的函数,您需要使用该Declare语句。例如:

Private Declare Function GetTempPath Lib "kernel32" _
     Alias "GetTempPathA" (ByVal nBufferLength As Long, _
     ByVal lpBuffer As String) As Long

See How to: Access DLLs in Excelon MSDN for more information.

有关详细信息,请参阅如何:访问MSDN上的 Excel 中的 DLL



To list the functions that are available, take a look at the Dependency Walkertool, which will list the exported functions from DLLs (and lots of other information).

要列出可用的函数,请查看Dependency Walker工具,该工具将列出从 DLL 导出的函数(以及许多其他信息)。