That's fairly straightforward. In the ThisOutlookSession module enter the following:
Code:
Option Explicit
Private Sub Application_Startup()
Dim xlApp As Object
Dim xlWb As Object
Const strWorkbook = "C:\Path\WorkbookName.xlsx"
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If Err <> 0 Then
Set xlApp = CreateObject("Excel.Application")
End If
On Error GoTo err_Handler
xlApp.Visible = True
'Open the workbook to input the data
If FileExists(strWorkbook) Then
Set xlWb = xlApp.workbooks.Open(strWorkbook)
Else
MsgBox "Workbook is missing!"
GoTo lbl_Exit
End If
'do seomething with the workbook here
lbl_Exit:
Set xlApp = Nothing
Set xlWb = Nothing
Exit Sub
err_Handler:
Err.Clear
GoTo lbl_Exit
End Sub
Private Function FileExists(filespec) As Boolean
Dim oFSO As Object
Set oFSO = CreateObject("Scripting.FileSystemObject")
If oFSO.FileExists(filespec) Then
FileExists = True
Else
FileExists = False
End If
lbl_Exit:
Set oFSO = Nothing
Exit Function
End Function