![]() |
#1
|
|||
|
|||
![]()
Hi all.
As per title, would like to know if I can get VBA to start a specific excel file when I open Outlook. There is a particular file I'd like to check on daily. Best way to not forget, is to have it launch every time i open Outlook. In my ThisOutlookSession I already have a script running to pop up the folder list when I hit send on a email so that I can choose the folder to store it in. I scrounged this up off the intertubes and it's not my doing. I'd like to somehow add to this script if possible so as to not have too much going on. Code:
Private Sub Application_ItemSend(ByVal Item As Object, _ Cancel As Boolean) Dim objNS As NameSpace Dim objFolder As MAPIFolder On Error Resume Next Set objNS = Application.Session If Item.Class = olMail Then Set objFolder = objNS.PickFolder If Not objFolder Is Nothing And _ IsInDefaultStore(objFolder) And _ objFolder.DefaultItemType = olMailItem Then Set Item.SaveSentMessageFolder = objFolder Else Set objFolder = _ objNS.GetDefaultFolder(olFolderSentMail) Set Item.SaveSentMessageFolder = objFolder End If End If Set objFolder = Nothing Set objNS = Nothing End Sub Public Function IsInDefaultStore(objOL As Object) As Boolean Dim objApp As Outlook.Application Dim objNS As Outlook.NameSpace Dim objInbox As Outlook.MAPIFolder Dim blnBadObject As Boolean On Error Resume Next Set objApp = objOL.Application If Err = 0 Then Set objNS = objApp.Session Set objInbox = objNS.GetDefaultFolder(olFolderInbox) Select Case objOL.Class Case olFolder If objOL.StoreID = objInbox.StoreID Then IsInDefaultStore = True Else IsInDefaultStore = False End If Case olAppointment, olContact, olDistributionList, _ olJournal, olMail, olNote, olPost, olTask If objOL.Parent.StoreID = objInbox.StoreID Then IsInDefaultStore = True Else IsInDefaultStore = False End If Case Else blnBadObject = True End Select Else blnBadObject = True End If If blnBadObject Then MsgBox "This function isn't designed to work " & _ "with " & TypeName(objOL) & _ " objects and will return False.", _ , "IsInDefaultStore" IsInDefaultStore = False End If Set objApp = Nothing Set objNS = Nothing Set objInbox = Nothing End Function |
#2
|
|||
|
|||
![]()
It might be quite disturbing to have the file open up every time you send mail.
This goes into the ThisOutlookSession module. It runs when Outlook is started. Code:
Private Sub Application_Startup() Dim oXLApp As Object Dim oXLwb As Object Dim oXLws As Object On Error Resume Next Set oXLApp = GetObject(, "Excel.Application") If Err.Number <> 0 Then Set oXLApp = CreateObject("Excel.Application") End If On Error GoTo 0 oXLApp.Visible = True Set oXLwb = oXLApp.Workbooks.Open("h:\Test\test.xlsx") Set oXLws = oXLwb.Sheets("Sheet2") oXLws.Select ExitRoutine: Set oXLws = Nothing Set oXLwb = Nothing Set oXLApp = Nothing End Sub |
#3
|
|||
|
|||
![]() Quote:
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Import Excel spreadsheet calendar data into Outlook 2010 | davesp | Outlook | 0 | 09-30-2013 09:26 AM |
Error when starting Word & Excel | mango | Word | 0 | 08-15-2013 07:53 AM |
![]() |
Catalin.B | Excel Programming | 2 | 09-07-2012 04:05 AM |
Is it possible to write down a number starting with zero in excel cell? | Rahmat_uk20 | Excel | 3 | 06-08-2012 02:26 AM |
How do I use an Excel form to populate and Excel spreadsheet | apostht | Excel | 0 | 05-21-2006 11:17 AM |