2009-09-09 12 views

risposta

2

Una possibilità è quella di verificare la presenza di VBE6.DLL in C: \ Programmi \ File comuni \ Microsoft Shared \ VBA \ VBA6. O curiosare nel registro cercando i riferimenti a quella DLL o alla stringa VBA.

Si noti che questo nome posizione/file potrebbe essere diverso per Office 2010 in quanto vi sono alcune modifiche nell'editor VBA.

+0

Questo non funziona per Office 365, sfortunatamente. –

0

Perché non si tenta una funzione come questa ... 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
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

I tag su questo sono VBA e Office. Sei sicuro di voler pubblicare una risposta che non sia correlata ai tag senza alcuna spiegazione? – Fionnuala

0

Stiamo parlando di componenti di Windows Installer. Il programma di installazione ha un'API, in cui è possibile richiedere se è installata una funzione/componente. ofcurse che api restituisca anche dove è installato il componente. se nessacary è possibile installare componenti mancanti.

l'unica cosa che serve è il componente e il prodotto guid.

see documentation

0

Il modo migliore per rilevare se è installato VBA è quello di utilizzare l'API MsiQueryFeatureState e chiedere di Windows Installer se la funzione è installato o non. Di seguito è riportato un codice di esempio in VB.NET, tuttavia è possibile codificarlo in qualsiasi lingua che consenta di chiamare i componenti COM (mi dispiace, non ho familiarità con 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 
Problemi correlati