Najlepszym sposobem, aby wykryć, czy jest zainstalowany VBA jest użycie API MsiQueryFeatureState i zapytać Instalatora Windows, czy funkcja jest zainstalowana lub nie. Poniżej znajduje się przykładowy kod, który robi to w VB.NET, jednak można go zakodować w dowolnym języku, który pozwala na wywołanie składników COM (przepraszam, nieznajomy z 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
To nie działa na Office 365, niestety. –