Open a .xls extention file using a command button

I am trying to open an excel spreadsheet in an access data form. I want a form with a command button that when pressed, opens an existing file that is in an excel spreadsheet.

I tried to write the code in vb, but it wont work.

Can I do this?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

This is a great intro to automation.

If this doesn't help, please submit the code you are trying to run with any errors you are getting.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
This is VBA code but it should still work...



On Error GoTo Err_Command59_Click
Dim ExcelSheet As Object
Set ExcelSheet = CreateObject("Excel.Application")

Set ExcelSheet = GetObject("C:\EXCEL.XLS")
ExcelSheet.Application.Visible = True = True

    Exit Sub

    MsgBox Err.Description
    Resume Exit_Command59_Click
'Add a reference to Microsoft Excel 10 Object Library
'from menu Project>Reference

This is an example:
    Dim objExcel, objWB, objSheet As Object
    Dim objItem

On Error GoTo Err
    Set objExcel = New Excel.Application
    Set objWB = & "\Analysis.xls")
    Set objSheet = objWB.Worksheets("YourWorkSheet)
    objSheet.cells(irow, icol) = "test data"   'irow and icol is the row/col you wish to change upon

    Set objSheet = Nothing
    Set objWB = Nothing
    Set objExcel = Nothing
    MsgBox "Data was entered into database", vbInformation
    Exit Sub
MsgBox "Error: " & Err.Description

~ fantasy ~
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.