2009-09-09 8 views
6

मेरे एक्सेल एडिन को एक्सेल के अनुप्रयोग विकल्प के लिए विजुअल बेसिक की आवश्यकता है ताकि इसे काम करने के लिए इंस्टॉल किया जा सके। मुझे यह पता लगाने में सक्षम होने के लिए मेरा इंस्टॉल (जो इनोसेटअप के साथ लिखा गया है) चाहते हैं कि वीबीए स्थापित है या नहीं, तो उपयोगकर्ता को चेतावनी दें।कैसे पता चलेगा कि कार्यालय का वीबीए घटक स्थापित है या नहीं?

मैं कैसे पता लगा सकता हूं कि विकल्प पहले से स्थापित है या नहीं? \ Program Files \ Common Files \ Microsoft साझा \ VBA \ VBA6:

alt text http://img35.imageshack.us/img35/9333/officeqm.png

उत्तर

2

एक संभावना यह सी में VBE6.DLL की उपस्थिति की जांच करने के लिए है। या उस डीएलएल या स्ट्रिंग वीबीए के संदर्भों की तलाश में रजिस्ट्री में पोक करें।

ध्यान दें कि यह स्थान/फ़ाइल नाम Office 2010 के लिए अलग हो सकता है क्योंकि वीबीए संपादक में कुछ बदलाव हैं।

+0

यह दुर्भाग्य से Office 365 के लिए काम नहीं करता है। –

0

तुम क्यों इस तरह एक समारोह कोशिश मत करो ... 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

इस पर टैग वीबीए और कार्यालय हैं। क्या आप वाकई एक उत्तर पोस्ट करना चाहते हैं जो किसी स्पष्टीकरण के बिना टैग से संबंधित नहीं है? – Fionnuala

0

हम Windows इंस्टालर घटकों के बारे में बात कर रहे हैं। इंस्टॉलर में एक एपीआई है, जहां आप एक सुविधा/घटक स्थापित किया गया है, तो आप अनुरोध कर सकते हैं। यह कि एसीआई भी वापस लौटाता है जहां घटक स्थापित है। यदि nessacary आप अनुपलब्ध घटकों को स्थापित कर सकते हैं।

केवल एक चीज जो आपको चाहिए, घटक अंडर उत्पाद गाइड है।

see documentation

0

अगर VBA स्थापित किया गया है पता लगाने के लिए सबसे अच्छा तरीका है MsiQueryFeatureState एपीआई का उपयोग और Windows इंस्टालर पूछना सुविधा या स्थापित नहीं है कि क्या करना है। नीचे कुछ नमूना कोड है जो इसे VB.NET में करता है, हालांकि आप इसे किसी भी भाषा में कोड कर सकते हैं जो आपको COM घटकों को कॉल करने की अनुमति देता है (क्षमा करें, इनोसेटअप से परिचित नहीं)।

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 
संबंधित मुद्दे