DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Excel Automation and Detection in VB6

  1. #1
    Join Date
    Aug 2004
    Posts
    104

    Excel Automation and Detection in VB6

    My application uses Excel automation. Therefore, I reference the Excel Object Library. I have 2 questions...

    1) How can I detect the presence of Excel on the system where my application is being used -- essentially to warn the user that the portion of the application that automates Excel will not work?

    2) Since my application references the Excel Object Library, if the application is installed on a system that does not have Excel installed, will the application even run if Excel is not present?

    Thanks
    Brian

  2. #2
    Join Date
    Dec 2003
    Posts
    2,750

    Re: Excel Automation and Detection in VB6

    Originally posted by bkh_vb1
    My application uses Excel automation. Therefore, I reference the Excel Object Library. I have 2 questions...

    1) How can I detect the presence of Excel on the system where my application is being used -- essentially to warn the user that the portion of the application that automates Excel will not work?
    Couple of different ways to do this. Since you're already using automation you could simply trap the error that will occur when you call CreateObject. Not elegant but you're certain to determine whether automation with Excel is available.

    You can also use the FindExecutable API function call to locate the path to the Excel executable:

    Code:
    
    Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
    
    Function ExcelPath() As String
    
    Dim sDummyFile As String
    Dim sDir As String
    Dim sFilePath As String * 255
    
    sDummyFile = "e:\My Documents\book1.xls"
    
    If FindExecutable(sDummyFile, sDir, sFilePath) > 32 Then
        ExcelPath = TrimNull(sFilePath)
    End If
    
    End Function
    
    Function TrimNull(item As String) As String
    
        Dim pos As Integer
       
        pos = InStr(item, Chr$(0))
        
        If pos Then
              TrimNull = Left$(item, pos - 1)
        Else: TrimNull = item
        End If
      
    End Function
    

    2) Since my application references the Excel Object Library, if the application is installed on a system that does not have Excel installed, will the application even run if Excel is not present?
    Your application will run but as soon as you attempt to instantiate Excel objects it will fail.

    In addition, if the application is to support multiple versions of Excel you will probably want to consider using late binding by not referencing the type library and declaring all Excel variables as Object.
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center