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
Printable View
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
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:
Private Sub Form_Load() MsgBox "Excel Installed : " & _ ReadRegistryKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Office\Excel") Unload Me End Sub
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
was not appropriate to my registry configuration, which showed Excel to be inside another level of path with a version-type description:Code:ReadRegistryKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Office\Excel")
[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
Drat, drat & double drat :p ! Okay, not beat yet, try this one:
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? :)VB Code:
Private Declare Function GetVersionEx Lib "kernel32" Alias _ "GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFO) As Long Private Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128 End Type Private Sub Form_Load() Dim version As OSVERSIONINFO version.dwOSVersionInfoSize = Len(version) If (version.dwPlatformId = 1) Then ' check for win 9x reg path ElseIf (version.dwPlatformId = 2) And (version.dwMajorVersion = 3 Or version.dwMajorVersion = 4) Then ' check for win nt reg path ElseIf (version.dwPlatformId = 2 And version.dwMajorVersion = 5) Then ' check for win 2000 reg path MsgBox ReadRegistryKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Office\Excel") ElseIf (version.dwPlatformId = 2 And version.dwMajorVersion = 6) Then ' check for win 2000 reg path End If End Sub
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 ;) :D ...
VB Code:
Private Sub Form_Load() On Error GoTo NotInstalled Dim XLAPP As Excel.Application Set XLAPP = New Excel.Application On Error GoTo ErrHandler 'Excel work here Set XLAPP = Nothing NotInstalled: MsgBox "EXCEL Not Installed!" ErrHandler: MsgBox "Other Error Occurred!" End Sub
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. :)
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! :D :D :D
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! :rolleyes:
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!
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! :)
That was a good one :p :D . This takes a little while to run, but searches your hard drive for the Excel program...Quote:
Just a quick question...
Usage:VB Code:
Private Declare Function SearchTreeForFile Lib "imagehlp" _ (ByVal RootPath As String, ByVal InputPathName As String, _ ByVal OutputPathBuffer As String) As Long Private Function SearchForFile(ByVal strFileName As String) As String Dim strTempBuffer As String Dim lngReturnVal As Long On Error GoTo errHandler strTempBuffer = String(255, 0) SearchForFile = "NOTFOUND" lngReturnVal = SearchTreeForFile("c:\", strFileName, strTempBuffer) If lngReturnVal <> 0 Then SearchForFile = Left(Trim(strTempBuffer), InStrRev(strTempBuffer, Right(strFileName, 1))) Else SearchForFile = "NOTFOUND" End If Exit Function errHandler: SearchForFile = "NOTFOUND" End Function
VB Code:
Private Sub Form_Load() MsgBox SearchForFile("EXCEL.EXE") End Sub
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!
:D :D :D
Dodge