Hi ,
I have a macro in excel and I am trying to run it from an access database.
All works well on my machine but when I moved to another it had a problem.
I have since realised that the reason is that the 2 versions of Excel are different . Mine is Excel 2003 and the other is Excel 2002. This means that my path has OFFICE11 and the other has OFFICE10 which is why I get the message that it can't find the path on the other machine.
I wanted to know if there was an easy way to handle this other than creating 2 macro's ( in access ) - 1 for 2002 users and 1 for 2003 users.
I am running access 97.
Any suggestions?
Thanks
Another method for you to consider for your Acc97 app would be to find the executable file ie the EXCEL.EXE file associated with an excel spreadsheet and base your decision on the fully formed return value filepath provided by a simple call to the windows API. This would then provide for targetting the excel.exe file wherever the installation of EXCEL actually is on the host PC
Paste the following into a new module and save it
- Option Explicit
-
Const cMAX_PATH = 260
-
Const ERROR_NOASSOC = 31
-
Const ERROR_FILE_NOT_FOUND = 2&
-
Const ERROR_PATH_NOT_FOUND = 3&
-
Const ERROR_BAD_FORMAT = 11&
-
Const ERROR_OUT_OF_MEM = 0
-
-
Private Declare Function apiFindExecutable Lib "SHELL32.DLL" _
-
Alias "FindExecutableA" _
-
(ByVal lpFile As String, _
-
ByVal lpDirectory As String, _
-
ByVal lpResult As String) _
-
As Long
-
-
Function fFindEXE(stFile As String, _
-
stDir As String) _
-
As String
-
-
Dim lpResult As String
-
Dim lngRet As Long
-
lpResult = Space(cMAX_PATH)
-
lngRet = apiFindExecutable(stFile, stDir, lpResult)
-
-
If lngRet > 32 Then
-
fFindEXE = lpResult
-
Else
-
Select Case lngRet:
-
Case ERROR_NOASSOC: fFindEXE = "Error: No Association"
-
Case ERROR_FILE_NOT_FOUND: fFindEXE = "Error: File Not Found"
-
Case ERROR_PATH_NOT_FOUND: fFindEXE = "Error: Path Not Found"
-
Case ERROR_BAD_FORMAT: fFindEXE = "Error: Bad File Format"
-
Case ERROR_OUT_OF_MEM: fFindEXE = "Error: Out of Memory"
-
End Select
-
End If
-
End Function
-
and type the followng into the immediate window where jim.xls represents the name of your spreadsheet and C:\jim represents the folder in which your spreadsheet is stored
- ?fFindEXE("jim.xls","c:\jim")
In the case of a default installation of office 2000 the return result would be
'C:\Program Files\Microsoft Office\Office\EXCEL.EXE'
You of course base your logic on whatever filepath is returned in your particular case
Regards
Jim