![]() |
|
#1
|
|||
|
|||
|
looking for some code to open a excel workbook.xlsm when ever Outlook is started.
|
|
#2
|
||||
|
||||
|
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 |
|
#3
|
||||
|
||||
|
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 |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Hyperlink to open another sheet in same workbook with filtered data
|
tarunbaweja | Excel Programming | 1 | 03-20-2016 06:52 AM |
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 |
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 |