SEARCH

Saturday, January 3, 2015

MS Access VBA how to open Excel File

Sometimes you need to open excel file from your ms access form, here is the code you may try..

Option Compare Database
Option Explicit


Sub OpenSpecific_xlFile()

    Dim oXL As Object
    Dim oExcel As Object
    Dim sFullPath As String
    Dim sPath As String
   
       
'   Buat Excel instance
    Set oXL = CreateObject("Excel.Application")
   
   
'  Handling control Property
    On Error Resume Next
    oXL.UserControl = True
    On Error GoTo 0
   
       
'   Full path file yang akan dibuka
    On Error GoTo ErrHandle
    sFullPath = CurrentProject.Path & "\FILECONTOH_INVOICE.xlsm"
   
   
'   buka file
    With oXL
        .Visible = True
        .Workbooks.Open (sFullPath)
    End With
   
   
ErrExit:
    Set oXL = Nothing
    Exit Sub
   
ErrHandle:
    oXL.Visible = False
    MsgBox Err.Description
    GoTo ErrExit
End Sub





Thanks

Hery (Freelance IT Trainer 081223344506)

0 comments:

Post a Comment

Silahkan isikan comment box untuk komentar Anda..