Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help Needed with Opening Excel Spreadsheet from Access

Status
Not open for further replies.

dpimental

Programmer
Jul 23, 2002
535
US
I need to be able to open Excel Spreadsheets from access. While I have been able to find and implement code that can do this, I get inconsistent results on different machines with different versions of msexcel.

Can anyone help me with a simple method of opening a spreadsheet in access when the machine could have different versions of msexcel on it?

David Pimental
(US, Oh)
 
I get inconsistent results
Doing WHAT ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
With the following code.
Code:
Dim oApp As Object, strPath As String
Dim excelPath As String
strPath = CurrentProject.Path & "\in_data\"
strFile = strPath & strFile

Set oApp = CreateObject("Excel.Application")

oApp.Workbooks.Open strFile
oApp.Visible = True

David Pimental
(US, Oh)
 
And what are the inconsistencies ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
On some machines, it just doesn't work. It can't find excel or some such error. I will try to get you the specific error.



David Pimental
(US, Oh)
 
THere error I am getting on some machines is this ...

ActiveX component can't create object



David Pimental
(US, Oh)
 
This may not fix your current problem, but you also want to make sure that you release the Excel object when you're through with it. If you don't, it will definitely cause problems. You'll need to add this at the end of your code:
Code:
Set oApp = Nothing
 
Thanks. I did it. Let me know if you have any other ideas.

David Pimental
(US, Oh)
 
If you are not automating Excel you may consider an API call. If not, I have seen this error before and it had to do with multiple version of MS Office installed on the computer.

If you surf microsofts site you will find API code for the apiShellExecute(). And before you say, oh no not API, keep this in mind. You can cut and paste the code right into a module within your Access DB and gain great power. One advantage is the system will launch which ever version of Excel is currently available. Second if you can use this code to directly open or print any file type supported on the host computer. Third is experience with API alls will bring further capability when you want to use them to Open Files or select directories. And fourth is that any problems or question you have can be addressed right here.
 
Thanks. I did an initial test. I got the code actually from The Access Web and it appears to work fine. I will test it Saturday on my problem pcs. Thanks for the help. I will let you know how it goes.

David Pimental
(US, Oh)
 
I am having the same problem. Could you post the code you got from The Access Web?

Thanks

Kim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top