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