受欢迎的博客标签

EXCEL VBA如何调用Windows API

Published

Windows API包括几千个可调用的函数,这些函数是Windows提供给应用程序与操作系统的接口,犹如“积木块”。

API 的 dll 在 windows 系统的 system32 目录下
图形界面相关的 API 在 USER32.dll 里,
进程、文件之类的操作在 kernel32.dll 里

在kernel32.dll中有一个 GetSystemDirectory()函数,可以到到Windows的系统路径。以下就是通过一个过程来调用这个函数的实例:

Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" _
(ByVal lpBuffer As String, ByVal nSize As Long) As Long
 Sub info()
Dim sPath As String * 260, lLen As Long
lLen = GetSystemDirectory(sPath, 260)
Text3 = Left(sPath, lLen)
VBA.MsgBox (Text3)
End Sub

detail:https://www.cnblogs.com/aademeng/articles/12950647.html