ExcelTip.Net留存知识帖 ---【注:附件之前被网盘供应商清空后,现已修复-现已修复-现已修复为本地下载!】
现在位置:首页 > E问E答 > Excel VBA > 如何用vba获取Windows目录和System目录?

如何用vba获取Windows目录和System目录?

作者:绿色风 分类: 时间:2022-08-17 浏览:143
楼主
wise
Q: 如何用vba获取Windows目录和System目录?
A:ALT+F11→插入模块→输入代码:
  1. Public Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
  2. Public Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
  3. Sub test()
  4.   Dim WindowsDirectory As String, SystemDirectory As String, x As Long
  5.   WindowsDirectory = Space(255)
  6.   SystemDirectory = Space(255)
  7.   x = GetWindowsDirectory(WindowsDirectory, 255)
  8.   x = GetSystemDirectory(SystemDirectory, 255)
  9.   MsgBox "Windows的安装目录是:" + WindowsDirectory + ",系统目录是:" + SystemDirectory
  10. End Sub
主要使用了两个API函数

如何用vba获取Windows目录和System目录?.rar
2楼
亡者天下
怎么应用呢?

免责声明

有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素, 经与ExcelTip.Net站长Apolloh商议并征得其同意, 现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示, 供有需要的人士查询使用,也慰缅曾经的论坛时代。 所示各个帖子的原作者如对版权有异议, 可与本人沟通提出,或于本站点留言,我们会尽快处理。 在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一

评论列表
sitemap