Access 获取office的安装路径【函数】
时间:2013-09-07 16:05 来源:Office中国 作者:andymark 阅读:次
很多人在安装的时候,不会留意安装路径,所以在需找安装目录的时候经常找不到。
office默认的安装路径是:C:\Program Files\Microsoft Office 但是我们一般不会安装到C盘,时间久了 我们就会忘记路径了。
下面发一下可以获取office 安装路径的函数。
Public Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias _
"RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) _
As Long
Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias _
"RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
ByVal lpReserved As Long, lpType As Long, _
ByVal lpData As String, lpcbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Const REG_SZ As Long = 1
Const KEY_ALL_ACCESS = &H3F
Const HKEY_LOCAL_MACHINE = &H80000002
Public Function OfficePath(OfficeID As String) As String
'用途:获取OFFICE安装路径
'用法: OfficePath "Access.Aplication"
Dim hKey As Long
Dim RetVal As Long
Dim sProgId As String
Dim sCLSID As String
Dim sPath As String
sProgId = OfficeID
RetVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\Classes\" & _
sProgId & "\CLSID", 0&, KEY_ALL_ACCESS, hKey)
If RetVal = 0 Then
Dim n As Long
RetVal = RegQueryValueEx(hKey, "", 0&, REG_SZ, "", n)
sCLSID = Space(n)
RetVal = RegQueryValueEx(hKey, "", 0&, REG_SZ, sCLSID, n)
sCLSID = Left(sCLSID, n - 1) 'drop null-terminator
RegCloseKey hKey
End If
RetVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _
"Software\Classes\CLSID\" & sCLSID & "\LocalServer32", 0&, _
KEY_ALL_ACCESS, hKey)
If RetVal = 0 Then
RetVal = RegQueryValueEx(hKey, "", 0&, REG_SZ, "", n)
sPath = Space(n)
RetVal = RegQueryValueEx(hKey, "", 0&, REG_SZ, sPath, n)
sPath = Left(sPath, n - 1)
OfficePath = sPath
office默认的安装路径是:C:\Program Files\Microsoft Office 但是我们一般不会安装到C盘,时间久了 我们就会忘记路径了。
下面发一下可以获取office 安装路径的函数。
Public Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias _
"RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) _
As Long
Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias _
"RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
ByVal lpReserved As Long, lpType As Long, _
ByVal lpData As String, lpcbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Const REG_SZ As Long = 1
Const KEY_ALL_ACCESS = &H3F
Const HKEY_LOCAL_MACHINE = &H80000002
Public Function OfficePath(OfficeID As String) As String
'用途:获取OFFICE安装路径
'用法: OfficePath "Access.Aplication"
Dim hKey As Long
Dim RetVal As Long
Dim sProgId As String
Dim sCLSID As String
Dim sPath As String
sProgId = OfficeID
RetVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\Classes\" & _
sProgId & "\CLSID", 0&, KEY_ALL_ACCESS, hKey)
If RetVal = 0 Then
Dim n As Long
RetVal = RegQueryValueEx(hKey, "", 0&, REG_SZ, "", n)
sCLSID = Space(n)
RetVal = RegQueryValueEx(hKey, "", 0&, REG_SZ, sCLSID, n)
sCLSID = Left(sCLSID, n - 1) 'drop null-terminator
RegCloseKey hKey
End If
RetVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _
"Software\Classes\CLSID\" & sCLSID & "\LocalServer32", 0&, _
KEY_ALL_ACCESS, hKey)
If RetVal = 0 Then
RetVal = RegQueryValueEx(hKey, "", 0&, REG_SZ, "", n)
sPath = Space(n)
RetVal = RegQueryValueEx(hKey, "", 0&, REG_SZ, sPath, n)
sPath = Left(sPath, n - 1)
OfficePath = sPath
(责任编辑:admin)
顶一下
(2)
100%
踩一下
(0)
0%
上一篇:导入导出Excel(.Xlsx)或(.Xls)数据到SQL Server
下一篇:没有了
下一篇:没有了
相关内容
- ·Access 获取office的安装路径【函数】
- ·导入导出Excel(.Xlsx)或(.Xls)数据到SQ
- ·浅析Access与Office其他成员之间交流数
- ·Access2003设置压缩和修复数据库的方法
- ·Access2003设置启动窗体与恢复原始设置
- ·妙用Office合并列数据 快速完成报表
- ·对 Microsoft Office 命令栏进行更多编
- ·SQL Server日期计算
- ·SQL语法参考
- ·XLS与MDB文件格式互换全攻略
- ·在Access中调用Excel无法彻底关闭
- ·Access导出到Excel提速之法
- ·Access朗读任意文本/使Access真人发声
- ·解决ACCESS XP 粘贴数字到EXCEL XP会变
- ·用VBA代码下载网络上的文件
- ·把子窗体的内容复制到EXCEL(子窗体可
最新内容