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?
MattWareConnect With a Mentor Commented:
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.

incongruentConnect With a Mentor Commented:
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
fantasy1001Connect With a Mentor Commented:
'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 ~
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.