Results 1 to 12 of 12

Thread: Excel presence?

  1. #1

    Thread Starter
    Junior Member Dodge's Avatar
    Join Date
    Aug 2002
    Location
    Kent, England
    Posts
    20

    Question Excel presence?

    Just a quick question...

    I'm trying to write a program that exports data to Microsoft Excel, and was wondering if there's a simple system call which would tell the program whether Excel was installed on the target system.

    Can anyone help me?

    Dodge
    Another interesting thread from Dodge

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    1) Start up a new vb exe app
    2) add the attached registry module
    3) Shove this into the forms code & run the app.
    VB Code:
    1. Private Sub Form_Load()
    2.     MsgBox "Excel Installed : " & _
    3.     ReadRegistryKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Office\Excel")
    4.    
    5.     Unload Me
    6. End Sub
    Attached Files Attached Files

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  3. #3

    Thread Starter
    Junior Member Dodge's Avatar
    Join Date
    Aug 2002
    Location
    Kent, England
    Posts
    20
    Thanks for the help, but when I tried it, it told me that Excel was not installed.

    This is not the case, because the app is installed!

    I checked the path in the registry, and found that the line

    Code:
    ReadRegistryKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Office\Excel")
    was not appropriate to my registry configuration, which showed Excel to be inside another level of path with a version-type description:

    [blue]HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Office\8.0\Excel[/blue]

    Is there any other way, for example searching within the registry, to look for the word "Excel"? The above strangeness makes me think that perhaps the version of Office I have is a different version from the one you have?

    But your help is gratefully received.

    Dodge
    Another interesting thread from Dodge

  4. #4
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Drat, drat & double drat ! Okay, not beat yet, try this one:
    VB Code:
    1. Private Declare Function GetVersionEx Lib "kernel32" Alias _
    2. "GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFO) As Long
    3.  
    4. Private Type OSVERSIONINFO
    5.     dwOSVersionInfoSize As Long
    6.     dwMajorVersion As Long
    7.     dwMinorVersion As Long
    8.     dwBuildNumber As Long
    9.     dwPlatformId As Long
    10.     szCSDVersion As String * 128
    11. End Type
    12.  
    13. Private Sub Form_Load()
    14.  
    15.     Dim version As OSVERSIONINFO
    16.     version.dwOSVersionInfoSize = Len(version)
    17.  
    18.     If (version.dwPlatformId = 1) Then
    19.         ' check for win 9x reg path
    20.     ElseIf (version.dwPlatformId = 2) And (version.dwMajorVersion = 3 Or version.dwMajorVersion = 4) Then
    21.         ' check for win nt reg path
    22.     ElseIf (version.dwPlatformId = 2 And version.dwMajorVersion = 5) Then
    23.        
    24.         ' check for win 2000 reg path
    25.         MsgBox ReadRegistryKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Office\Excel")
    26.        
    27.     ElseIf (version.dwPlatformId = 2 And version.dwMajorVersion = 6) Then
    28.         ' check for win 2000 reg path
    29.     End If
    30. End Sub
    This you should be able to add on top of the above code I gave you - it's to check which versions of windows you have. I've given you a win2000 example, & you've found the key to you os, can anyone else paste some more excel app registry key locations?
    Last edited by alex_read; Sep 9th, 2002 at 05:46 AM.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  5. #5
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    I'm suprised I'm going to write this one, but it's an "if all else fails " bit of code which'll do the same trick ...

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3.     On Error GoTo NotInstalled
    4.    
    5.     Dim XLAPP As Excel.Application
    6.     Set XLAPP = New Excel.Application
    7.    
    8.         On Error GoTo ErrHandler
    9.         'Excel work here
    10.        
    11.     Set XLAPP = Nothing
    12.  
    13. NotInstalled:
    14.     MsgBox "EXCEL Not Installed!"
    15.    
    16. ErrHandler:
    17.     MsgBox "Other Error Occurred!"
    18. End Sub

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  6. #6

    Thread Starter
    Junior Member Dodge's Avatar
    Join Date
    Aug 2002
    Location
    Kent, England
    Posts
    20
    Thanks again, but in the same vein I checked on one of my colleagues' PCs and found the same registry entry for Excel as I found for my own.

    I think that the version part is supposed to be there...

    But, is it possible to look into the system in the same way that the Windows Control Panel program does, and find an entry for Microsoft Excel??? This could be another way to solve my problem.

    Your efforts and help are much appreciated.
    Another interesting thread from Dodge

  7. #7

    Thread Starter
    Junior Member Dodge's Avatar
    Join Date
    Aug 2002
    Location
    Kent, England
    Posts
    20
    Alex

    I was just thinking about the "use an error handler if all else fails" approach, when you just posted it.

    However, what about the Control Panel's way of looking into the system using technology similar to that used in the "Add/Remove Programs" option? Is this viable?

    But, if it's good enough for you to use the error handler method (!), then it's good enough for me!!!

    I use VB5 and Windows 98 v2

    Your reward will be great in the hereafter!
    Another interesting thread from Dodge

  8. #8
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Which control pannel app are you referring to.
    I just thought too, it'd be the office version rather than the windows version which'll determine the registry entry - ignore the above, sorry!

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  9. #9

    Thread Starter
    Junior Member Dodge's Avatar
    Join Date
    Aug 2002
    Location
    Kent, England
    Posts
    20
    The [b]Control Panel[/] app which I am referring to is the

    "Add/Remove Programs" app. This obviously lists installed applications, and perhaps is available to VB through whatever method.

    Does anyone know it?

    P.S. I'm probably going to use the error handler method (feeling lazy and like cheating at the moment )

    Thanks a lot!
    Another interesting thread from Dodge

  10. #10
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Ah, okay the add/remove programs option isn't really viable here. It'll only show an entry for MS Excel in the uninstall programs list if it's only excel which has been installed. If you have the office cd & put word & excel on together, only 1 item will show in the uninstall list for Ms Office.

    I've thought of another way though, you can use the api to search for Excel.exe on the current pc. I'll see if I can write a sample of this for you!

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  11. #11
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Just a quick question...
    That was a good one . This takes a little while to run, but searches your hard drive for the Excel program...
    VB Code:
    1. Private Declare Function SearchTreeForFile Lib "imagehlp" _
    2. (ByVal RootPath As String, ByVal InputPathName As String, _
    3. ByVal OutputPathBuffer As String) As Long
    4.  
    5. Private Function SearchForFile(ByVal strFileName As String) As String
    6.     Dim strTempBuffer As String
    7.     Dim lngReturnVal As Long
    8.    
    9.     On Error GoTo errHandler
    10.    
    11.     strTempBuffer = String(255, 0)
    12.     SearchForFile = "NOTFOUND"
    13.  
    14.     lngReturnVal = SearchTreeForFile("c:\", strFileName, strTempBuffer)
    15.    
    16.     If lngReturnVal <> 0 Then
    17.         SearchForFile = Left(Trim(strTempBuffer), InStrRev(strTempBuffer, Right(strFileName, 1)))
    18.     Else
    19.         SearchForFile = "NOTFOUND"
    20.     End If
    21.    
    22.     Exit Function
    23.    
    24. errHandler:
    25.     SearchForFile = "NOTFOUND"
    26. End Function
    Usage:
    VB Code:
    1. Private Sub Form_Load()
    2.     MsgBox SearchForFile("EXCEL.EXE")
    3. End Sub

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  12. #12

    Thread Starter
    Junior Member Dodge's Avatar
    Join Date
    Aug 2002
    Location
    Kent, England
    Posts
    20
    Alex,

    Enough! You have been completely helpful here, and I'm using the "error trapping" method to determine whether Excel is present.

    Anyway, it was a quick question... it was just the answer(s) that went on a bit...

    Thanks very much for your assistance. Solution is now implemented. Have a nice day!



    Dodge
    Another interesting thread from Dodge

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width