How do I know if the VBA Office component is installed?

For the Excel add-in to work, the Visual Basic for Applications option must be installed in Excel. I would like my installation (which is written with InnoSetup) to be able to detect if VBA is installed and to alert the user if this is not the case.

How can I determine if this option is set?

alt text

+6
vba excel-vba excel ms-office
source share
5 answers

One possibility is to check for the presence of VBE6.DLL in C: \ Program Files \ Common Files \ Microsoft Shared \ VBA \ VBA6. Or confuse the registry by looking for links to this DLL or VBA string.

Please note that this location / file name may be different for Office 2010, as there are some changes in the VBA editor.

+2
source share

Why don't you try this feature ... found here

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
source share
 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
source share

We are talking about the components of the Windows Installer. The installer has an API where you can request the installation of a component / component. ofcurse so that api also returns to where the component is installed. if nessacary you can install the missing components.

the only thing you need is the und product guid component.

see documentation

0
source share

The best way to determine if VBA is installed is to use the MsiQueryFeatureState API and ask the Windows installer if this function is installed or not. Below is an example of the code that does this in VB.NET, however you can encode it in any language that allows you to call COM components (sorry, not familiar with InnoSetup).

 Private Declare Function MsiQueryFeatureState Lib "Msi" Alias "MsiQueryFeatureStateA" (ByVal Product As String, ByVal Feature As String) As Long Public Function FVbaAvailable() As Boolean Dim objExcelApp As Object Dim strProductCode As String Dim nState As Long Dim fAvailable As Boolean = False Try ' Start an Excel instance and get the product code. objExcelApp = CreateObject("Excel.Application") strProductCode = DirectCast(objExcelApp.ProductCode, String) ' Get FeatureState for the VBAFiles Feature. nState = MsiQueryFeatureState(strProductCode, "VBAFiles") If (nState = 1) OrElse (nState = 3) OrElse (nState = 4) Then ' VBA is available. fAvailable = True End If ' Clean up. objExcelApp.Quit() Runtime.InteropServices.Marshal.FinalReleaseComObject(objExcelApp) objExcelApp = Nothing Catch ex As Exception Trace.WriteLine(ex.Message) End Try Return fAvailable End Function 
0
source share

All Articles