Has User got Excel

T

TonyT

As the front end of my db is an mde, what is the most robust method of
determining if a clients pc has Excel or Word installed on it before
atempting to export to them. A file exists check in Office folder or an
application object check or another way entirely?

Currently I just catch the error, but I'm not happy with that approach.
 
J

Jack Leach

I forget where it came form but I seem to remember building it from something
a little less user-friendly a while back. It's made to return the version
number for a given office application, but I presume it will let you know
(one way or another) if it doesn't exist.

Copy/Paste into a module and call fGetOfficeEXE() to run the API that
checks the reg for version...



'==========================
Option Compare Database
Option Explicit

Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias _
"RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) _
As Long

Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias _
"RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
ByVal lpReserved As Long, lpType As Long, _
ByVal lpData As String, lpcbData As Long) As Long
'Note that if you declare the lpData parameter as String,
'you must pass it ByVal.


Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long)
As Long

Const REG_SZ As Long = 1
Const KEY_ALL_ACCESS = &H3F
Const HKEY_LOCAL_MACHINE = &H80000002

Public Enum eOfficeApp
eOfficeAppaccess = 0
eOfficeAppExcel = 1
eOfficeAppoutlook = 2
eOfficeAppPowerpoint = 3
eOfficeAppword = 4
eOfficeAppFrontPage = 5
End Enum


Public Function fGetOfficeEXE(lApp As eOfficeApp) As String
Dim hKey As Long
Dim RetVal As Long
Dim sProgId As String
Dim sCLSID As String
Dim sPath As String

Select Case lApp
Case 0: sProgId = "Access"
Case 1: sProgId = "Excel"
Case 2: sProgId = "Outlook"
Case 3: sProgId = "Powerpoint"
Case 4: sProgId = "Word"
Case 5: sProgId = "FrontPage"
End Select

sProgId = sProgId & ".Application"

'First, get the clsid from the progid
'from the registry key:
'HKEY_LOCAL_MACHINE\Software\Classes\<PROGID>\CLSID
RetVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\Classes\" & _
sProgId & "\CLSID", 0&, KEY_ALL_ACCESS, hKey)
If RetVal = 0 Then
Dim n As Long
RetVal = RegQueryValueEx(hKey, "", 0&, REG_SZ, "", n)
sCLSID = Space(n)
RetVal = RegQueryValueEx(hKey, "", 0&, REG_SZ, sCLSID, n)
sCLSID = Left(sCLSID, n - 1) 'drop null-terminator
RegCloseKey hKey
End If

'Now that we have the CLSID, locate the server path at
'HKEY_LOCAL_MACHINE\Software\Classes\CLSID\
' {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx}\LocalServer32

RetVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _
"Software\Classes\CLSID\" & sCLSID & "\LocalServer32", 0&, _
KEY_ALL_ACCESS, hKey)
If RetVal = 0 Then
RetVal = RegQueryValueEx(hKey, "", 0&, REG_SZ, "", n)
sPath = Space(n)

RetVal = RegQueryValueEx(hKey, "", 0&, REG_SZ, sPath, n)
sPath = Left(sPath, n - 1)
'MsgBox sPath
RegCloseKey hKey
End If

fGetOfficeEXE = sPath
End Function

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
J

Jack Leach

It's made to return the version
number for a given office application

Sorry, this one returns the executable for the program, not the version
number (don't know where that one went...)

Unfortunately I don't have access to a computer that doesn't have any of
these programs installed, so I can't test on a non-existant.

It looks like the function's going to try to return null (sPath) if there's
nothing installed (oops!). You can either change the return type of
fGetOfficeEXE to a Variant or throw an Nz() wrapper around the return:


fGetOfficeEXE = Nz(sPath, "")


hth
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
A

Alex Dybenko

Hi,
you can also try to initiate application object, and if not fail - then
application is installed:

set oApp=CreateObject("Excel.Application")

BTW, I don’t think that excel need to be installed in order to export to
excel file in access

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com
 
T

TonyT

thank you both, I'll have a play with both approaches and let you know what
route I take.

thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top