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 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
No comments:
Post a Comment