Mike,

Try the following, which doesn't rely on knowing which version of Excel 
you are using and will work for most programs. Just supply the executable 
name to the function e.g. excel.exe or msaccess.exe

'****************************************************************

Define HKEY_LOCAL_MACHINE -2147483646
Define  REG_SZ 1
Define  ERROR_SUCCESS  0
 
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Integer) As 
Integer
Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal 
hKey As Integer, ByVal lpSubKey As String, phkResult As Integer) As 
Integer
Declare Function RegQueryValueEx Lib "advapi32.dll" Alias 
"RegQueryValueExA" (ByVal hKey As Integer, ByVal lpValueName As String, 
ByVal lpReserved As Integer, lpType As Integer, lpData As string, lpcbData 
As Integer) As Integer
declare function GetExePath (Byval ExeName as string) as string
'
'****************************************************************
' 
function GetExePath (Byval ExeName as string) as string

Dim lRetVal As integer
Dim hKey,sType,Ssize As integer
Dim sValue,SKey As String

GetExePath="c:\program files\"
sType =REG_SZ
Ssize =1024

SKey="Software\Microsoft\Windows\CurrentVersion\App Paths\" & ExeName 
lRetVal = RegOpenKey(HKEY_LOCAL_MACHINE,SKey,hKey)

If lRetVal <> ERROR_SUCCESS Then
        exit function
Else
        sValue =string$(ssize,chr$(32))

        lRetVal = RegQueryValueEx(hKey,"Path", 0, sType , sValue, Ssize )
        If lRetVal <> ERROR_SUCCESS Then
                exit function
        Else
                GetExePath =rtrim$(sValue)
                if right$(rtrim$(sValue),1)<>"\" then
                        GetExePath=rtrim$(sValue) & "\"
                end if
        End If
        lRetVal = RegCloseKey(hKey)
End If

'****************************************************************

Regards,

Ian Hull


Greater Manchester Transportation Unit
Salisbury House
Granby Row
Manchester
M1 7AH

Internal Tel: 815 2059
Tel:      0161 455 2059
Fax:      0161 455 2071
E-mail:   [EMAIL PROTECTED]
Website:  http://www.agma.gov.uk/Units/TransportUnit.htm





[EMAIL PROTECTED]
25/10/2005 19:19

 
        To:     [email protected]
        cc: 
        Subject:        MI-L MapBasic opening Excel


Hello all,
I have a MapBasic app writing out a comma delimited file, then  launching
Excel, where a macro opens and formats the data.

Here is the mb code:
sReportXLS = "myreport.xls"
sRunline = "C:\Program Files\Microsoft Office\Office11\Excel /e "  +
chr$(34)  + sReportXLS  + chr$(34)
Run Program  sRunline

My, question: is it possible to obtain the machine's Excel.exe path, 
rather
than having it hardwired?  I want to be able to handle unexpected Excel
setups.

Thanks,

Mike



**********************************************************************

This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are addressed. If 
you have received this email in error please notify the system manager.

This footnote also confirms that this email message has been swept by 
MIMEsweeper for the presence of computer viruses.

Please contact [EMAIL PROTECTED] with any queries.

**********************************************************************

Reply via email to