Opening Excel file from within Access

bijondhanbad

Registered User.
Local time
Today, 05:20
Joined
Sep 8, 2006
Messages
33
I want to open an Excel file using a command button in an Access form. This Excel file then needs to be updated and saved subsequently.
Can someone help me out with a code for this?

Regards
bijon
 
You should be able to do this by using the excel application object. Basically you open the spreadsheet in access and use vb just like you would in excel to manipulate stuff. Here's a bit of code I used to get a date from a cell in a spreadsheet:

On Error GoTo Err_mfncGetCurrentXLSDate

Code:
    Dim xlApp As New Excel.Application      'Application Object
    Dim xlwrkBk As Excel.Workbook           'Workbook Object
    Dim xlSheet As Excel.Worksheet          'Spreadsheet Object
    Dim strXLS As String                    'Spreadsheet
    
    'Spreadsheet
    strXLS = c:/files/mysheet.xls

    'Set the spreadsheet
    Set xlwrkBk = xlApp.Workbooks.Open(strXLS)

    'Set the worksheet
    Set xlSheet = xlwrkBk.Worksheets(1)
    
    mfncGetCurrentXLSDate = CVDate(Trim(Left(xlSheet.Cells(1, 1), 12)))
    
    xlwrkBk.Close           'Close the spreadsheet object
    Set xlSheet = Nothing   'Delete the worksheet object
    Set xlwrkBk = Nothing   'Delete the spreadsheet object
    xlApp.Quit              'Close the excel application object
    Set xlApp = Nothing     'Delete the application object
.
.
.

The xlSheet.Cells thing is where it looks just like it would if you where in excel doing all of this...
 

Users who are viewing this thread

Back
Top Bottom