Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-08-2016, 11:13 AM
gbaker gbaker is offline Open a WORKBOOK FROM OUTLOOK Windows 7 32bit Open a WORKBOOK FROM OUTLOOK Office 2010 32bit
Competent Performer
Open a WORKBOOK FROM OUTLOOK
 
Join Date: May 2012
Posts: 111
gbaker is on a distinguished road
Default Open a WORKBOOK FROM OUTLOOK


looking for some code to open a excel workbook.xlsm when ever Outlook is started.
Reply With Quote
  #2  
Old 04-08-2016, 09:50 PM
gmayor's Avatar
gmayor gmayor is offline Open a WORKBOOK FROM OUTLOOK Windows 10 Open a WORKBOOK FROM OUTLOOK Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
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 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
  #3  
Old 04-08-2016, 10:44 PM
gmayor's Avatar
gmayor gmayor is offline Open a WORKBOOK FROM OUTLOOK Windows 10 Open a WORKBOOK FROM OUTLOOK Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
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 of
Default

Duplicated in error
__________________
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
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Open a WORKBOOK FROM OUTLOOK Hyperlink to open another sheet in same workbook with filtered data tarunbaweja Excel Programming 1 03-20-2016 06:52 AM
Open a WORKBOOK FROM OUTLOOK How to open one Workbook from another in VBA 2016 OldAl Excel Programming 1 01-12-2016 06:58 PM
data entered in one workbook should be updated in other relevant workbook based on the date vedha Excel 0 04-24-2015 08:45 PM
Open a WORKBOOK FROM OUTLOOK Need to open an Excel WorkBook from Word VBA Pierre-Hugues Word VBA 4 10-07-2013 06:27 AM
Unable to open Excel 97-2003 workbook J Partridge Excel 1 11-07-2010 03:26 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:25 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft