Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-09-2015, 07:20 AM
NMGMarques NMGMarques is offline Starting Excel spreadsheet on Outlook start Windows 7 32bit Starting Excel spreadsheet on Outlook start Office 2010 32bit
Novice
Starting Excel spreadsheet on Outlook start
 
Join Date: Mar 2014
Posts: 6
NMGMarques is on a distinguished road
Default Starting Excel spreadsheet on Outlook start

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
Reply With Quote
  #2  
Old 06-09-2015, 09:54 AM
niton niton is offline Starting Excel spreadsheet on Outlook start Windows 7 64bit Starting Excel spreadsheet on Outlook start Office 2010 64bit
Competent Performer
 
Join Date: Jul 2012
Posts: 102
niton is on a distinguished road
Default

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
Reply With Quote
  #3  
Old 06-09-2015, 11:07 PM
NMGMarques NMGMarques is offline Starting Excel spreadsheet on Outlook start Windows 7 32bit Starting Excel spreadsheet on Outlook start Office 2010 32bit
Novice
Starting Excel spreadsheet on Outlook start
 
Join Date: Mar 2014
Posts: 6
NMGMarques is on a distinguished road
Default

Quote:
Originally Posted by niton View Post
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.
Hadn't even considered that. Thanks for pointing it out And the script works perfect. Much thanks!
Reply With Quote
Reply



Similar Threads
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
Starting Excel spreadsheet on Outlook start Excel stops responding after starting macro 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

Other Forums: Access Forums

All times are GMT -7. The time now is 09:54 AM.


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