首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何知道是否安装了Office的VBA组件?

如何知道是否安装了Office的VBA组件?
EN

Stack Overflow用户
提问于 2009-09-09 16:13:55
回答 5查看 18.2K关注 0票数 6

我的Excel外接程序需要安装Excel的Visual Basic for Applications选项才能工作。我希望我的安装(它是用InnoSetup编写的)能够检测是否安装了VBA,并在没有安装时警告用户。

如何检测选件是否已安装?

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2009-09-09 20:19:39

一种可能是检查C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6中是否存在VBE6.DLL。或者在注册表中查找对该DLL或字符串VBA的引用。

请注意,对于Office 2010,此位置/文件名可能有所不同,因为VBA编辑器中有一些更改。

票数 2
EN

Stack Overflow用户

发布于 2010-05-25 07:13:45

你为什么不试试像这样的函数...found here

代码语言:javascript
运行
复制
Option Explicit
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long

Private Sub cmdCheck_Click()
MsgBox "Exist ???    =" & CheckForComponent("user32.dll")
End Sub

Private Function CheckForComponent(ComPath As String) As Boolean
Dim Ret As Long
Ret = LoadLibrary(ComPath)
FreeLibrary Ret

If Ret = 0 Then
        CheckForComponent = False
    Else
        CheckForComponent = True
End If

End Function 
票数 0
EN

Stack Overflow用户

发布于 2011-01-14 20:41:14

代码语言:javascript
运行
复制
public static  class VbePrerequisiteDetector {
    private const string VbeInstallationPathKey = @"SOFTWARE\Microsoft\VBA";
    private const string Vbe6InstallationPathValue = "Vbe6DllPath";
    private const string Vbe7InstallationPathValue = "Vbe7DllPath";

    /// <summary>
    /// Return true if VBE6 installed. VBE6 is prerequisite for for Office2003 and Office2007
    /// </summary>
    /// <returns>Return true if VBE6 installed.</returns>
    public static bool IsVbe6Installed() {
        try {
            RegistryKey vbaPathKey = Registry.LocalMachine.OpenSubKey(VbeInstallationPathKey);

            if (vbaPathKey != null) {
                if (vbaPathKey.GetValue(Vbe6InstallationPathValue) != null) {
                    string pathToVbe = (string)vbaPathKey.GetValue(Vbe6InstallationPathValue);
                    if (File.Exists(pathToVbe)) {
                        return true;
                    }

                }
            }
        }
        catch (Exception) {
            //Ignore all exceptions
        }
        return false;
    }

    /// <summary>
    /// Return true if VBE7 installed. VBE7 is prerequisite for for Office2010
    /// </summary>
    /// <returns>Return true if VBE7 installed.</returns>
    public static bool IsVbe7Installed() {
        try {
            RegistryKey vbaPathKey = Registry.LocalMachine.OpenSubKey(VbeInstallationPathKey);

            if (vbaPathKey != null) {
                if (vbaPathKey.GetValue(Vbe7InstallationPathValue) != null) {
                    string pathToVbe = (string)vbaPathKey.GetValue(Vbe7InstallationPathValue);
                    if (File.Exists(pathToVbe)) {
                        return true;
                    }

                }
            }
        }
        catch (Exception) {
            //Ignore all exceptions
        }
        return false;
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1400643

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档