View Single Post
 
Old 04-08-2016, 09:50 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote