473,406 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

trying to use access to open an excel spreadsheet when 2 versions of excel are in use

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
Sep 25 '07 #1
5 1355
ADezii
8,834 Expert 8TB
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
Before you do anything, verify the Excel Version. I'm not sure if this will work in Access 97, but it is worth a try:
Expand|Select|Wrap|Line Numbers
  1. Dim objExcel As Excel.Application, strExcelPath As String
  2.  
  3. Set objExcel = New Excel.Application
  4.  
  5. Select Case objExcel.Version
  6.   Case "10.0"
  7.     strExcelPath = "C:\Program Files\Microsoft Office\OFFICE10\"
  8.     'processing for Excel 2002
  9.     '...
  10.   Case "11.0"
  11.     strExcelPath = "C:\Program Files\Microsoft Office\OFFICE11\"
  12.     'processing for Excel 2003
  13.     '...
  14. End Select
  15.  
  16. 'Debug.Print "Excel Path = " & strExcelPath
  17.  
  18. Set objExcel = Nothing
Sep 25 '07 #2
Jim Doherty
897 Expert 512MB
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

Expand|Select|Wrap|Line Numbers
  1.  Option Explicit 
  2. Const cMAX_PATH = 260
  3. Const ERROR_NOASSOC = 31
  4. Const ERROR_FILE_NOT_FOUND = 2&
  5. Const ERROR_PATH_NOT_FOUND = 3&
  6. Const ERROR_BAD_FORMAT = 11&
  7. Const ERROR_OUT_OF_MEM = 0
  8.  
  9. Private Declare Function apiFindExecutable Lib "SHELL32.DLL" _
  10.     Alias "FindExecutableA" _
  11.     (ByVal lpFile As String, _
  12.     ByVal lpDirectory As String, _
  13.     ByVal lpResult As String) _
  14.     As Long
  15.  
  16. Function fFindEXE(stFile As String, _
  17.                     stDir As String) _
  18.                     As String
  19.  
  20. Dim lpResult As String
  21. Dim lngRet As Long
  22.     lpResult = Space(cMAX_PATH)
  23.     lngRet = apiFindExecutable(stFile, stDir, lpResult)
  24.  
  25.     If lngRet > 32 Then
  26.         fFindEXE = lpResult
  27.     Else
  28.         Select Case lngRet:
  29.             Case ERROR_NOASSOC: fFindEXE = "Error: No Association"
  30.             Case ERROR_FILE_NOT_FOUND: fFindEXE = "Error: File Not Found"
  31.             Case ERROR_PATH_NOT_FOUND: fFindEXE = "Error: Path Not Found"
  32.             Case ERROR_BAD_FORMAT: fFindEXE = "Error: Bad File Format"
  33.             Case ERROR_OUT_OF_MEM: fFindEXE = "Error: Out of Memory"
  34.         End Select
  35.     End If
  36. End Function
  37.  

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

Expand|Select|Wrap|Line Numbers
  1.  ?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
Sep 26 '07 #3
ADezii
8,834 Expert 8TB
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
Actually, there is a simpler method:

Dim objExcel As Excel.Application, strExcelPath As String
Set objExcel = New Excel.Application

strExcelPath = objExcel.Path & "\"

Debug.Print strExcelPath

Set objExcel = Nothing

OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. C:\Program Files\Microsoft Office\Office\
Sep 26 '07 #4
Jim Doherty
897 Expert 512MB
Actually, there is a simpler method:

Dim objExcel As Excel.Application, strExcelPath As String
Set objExcel = New Excel.Application

strExcelPath = objExcel.Path & "\"

Debug.Print strExcelPath

Set objExcel = Nothing

OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. C:\Program Files\Microsoft Office\Office\

Hey ...way to go ADezzi now why didn't I think of that one Head full of code or cold maybe haha

Jim
Sep 26 '07 #5
cyberdwarf
218 Expert 100+
Something like this might be more useful (I assume that the Excel installation path might be changed from the default and therefore not prove to be so reliable):-
Expand|Select|Wrap|Line Numbers
  1. Dim objExcel As Excel.Application, strExcelPath As String
  2. Set objExcel = New Excel.Application
  3.  
  4. Debug.Print objExcel.Version
  5. Set objExcel = Nothing
Steve
Sep 26 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
6
by: Paul | last post by:
I was wondering if anyone has had an issue where using vba code to read an excel file and import the data into an access table some records are not imported from the excel file. It seems looking at...
0
by: ImraneA | last post by:
Hi there Many thanks to those people who contributed to this group, helped me greatly. Enclose, my code, hope it helps others :- Public Function Export_Excel_9(tbx1 As Variant, tbx2 As...
18
by: Andre Laplume via AccessMonster.com | last post by:
I have inherited a bunch of dbs which are are shared among a small group in my dept. We typically use the dbs to write queries to extract data, usually dumping it into Excel. Most dbs originated...
37
by: jasmith | last post by:
How will Access fair in a year? Two years? .... The new version of Access seems to service non programmers as a wizard interface to quickly create databases via a fancy wizard. Furthermore, why...
4
by: Jules48 | last post by:
I store comprehensive details of customers' "transactions" in Access (2000). At the moment, I (or my staff) duplicate entry of the information in an Excel spreadsheet which we use to extract stats...
1
by: garry.oxnard | last post by:
Can anyone help me to solve a problem which involves switching from Access to Excel (then back to Access) programatically please? I have an Excel template which, on open, also opens an Access...
1
by: smaczylo | last post by:
Hello, I've recently been asked to work with Microsoft Access, and while I feel quite comfortable with Excel, I'm at a complete loss with databases. If someone could help me with this issue I'm...
7
by: semijoyful | last post by:
OS: Win XP SP2 Access version: 2003 Excel version: 2003 I am new at this, as I am sure you have gathered from this post title:) I am working on a form where users can input data in Access and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.