Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-16-2014, 07:50 AM
WeDonNeedNoSteenkgRibbons's Avatar
WeDonNeedNoSteenkgRibbons WeDonNeedNoSteenkgRibbons is offline Peculiar Outlook VBA item, Application_Quit Windows XP Peculiar Outlook VBA item, Application_Quit Office 2003
Novice
Peculiar Outlook VBA item, Application_Quit
 
Join Date: Jul 2014
Posts: 23
WeDonNeedNoSteenkgRibbons is on a distinguished road
Default Peculiar Outlook VBA item, Application_Quit

Below is my in class module Class1 in Project1 (VbaProject.OTM) (I'm just reading from the Project pane). When I close outlook, I get
Code:
Run-time error '424':
Object required.
(2 buttons, debug and end)
If you click debug, you see the For Each line highlighted in yellow as it's stopped there, and more peculiarly, one second later, the VBA window disappears and you get Dr. Watson asking if you want to report the crash to MS.


Code:
Private Sub Application_Quit()
    Dim olItems As Outlook.Items, olItem As Object, i As Integer
    
    For Each olItem In olItems
        i = i + 1
    Next
End Sub
OL 2007. It happens 100% of the time as I quit Outlook. Advice?
Reply With Quote
  #2  
Old 07-16-2014, 11:42 AM
niton niton is offline Peculiar Outlook VBA item, Application_Quit Windows 7 64bit Peculiar Outlook VBA item, Application_Quit Office 2010 64bit
Competent Performer
 
Join Date: Jul 2012
Posts: 102
niton is on a distinguished road
Default

Object required. Here is sample code.

Code:
 
Private Sub Application_Quit()
    Dim olItems As Outlook.Items, olItem As Object, i As Integer
 
    Dim olInbox As Outlook.MAPIFolder
 
    Set olInbox = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
 
    Set olItems = olInbox.Items  ' <----
 
    For Each olItem In olItems
        i = i + 1
    Next
 
    Debug.Print " Number of items in Inbox: " & i
    MsgBox " Number of items in Inbox: " & i
End Sub
Reply With Quote
  #3  
Old 07-16-2014, 11:47 AM
WeDonNeedNoSteenkgRibbons's Avatar
WeDonNeedNoSteenkgRibbons WeDonNeedNoSteenkgRibbons is offline Peculiar Outlook VBA item, Application_Quit Windows XP Peculiar Outlook VBA item, Application_Quit Office 2003
Novice
Peculiar Outlook VBA item, Application_Quit
 
Join Date: Jul 2014
Posts: 23
WeDonNeedNoSteenkgRibbons is on a distinguished road
Default

Okay, good stuff.

My goal is to interrupt quitting when there are messages open, to display a concatenated list of them in a msgbox, and abort quitting if chosen; maybe throwing them in a combobox so I could click into one. So I think the first thing I want is a collection of open messages that I can For Each or something if you or someone knows the object.

I know I could explode the taskbar icon and see them that way, but I might neglect to do that. This, on the Quit event, would always stick the prompt in my face.

Thanks.
Reply With Quote
  #4  
Old 07-16-2014, 02:29 PM
niton niton is offline Peculiar Outlook VBA item, Application_Quit Windows 7 64bit Peculiar Outlook VBA item, Application_Quit Office 2010 64bit
Competent Performer
 
Join Date: Jul 2012
Posts: 102
niton is on a distinguished road
Default

Application_Quit cannot be cancelled. http://msdn.microsoft.com/en-us/libr...ffice.15).aspx

Notice the difference in Application_ItemSend which is much more useful. http://msdn.microsoft.com/en-us/libr...ffice.15).aspx

Last edited by niton; 07-16-2014 at 02:31 PM. Reason: Typo
Reply With Quote
  #5  
Old 07-16-2014, 02:55 PM
WeDonNeedNoSteenkgRibbons's Avatar
WeDonNeedNoSteenkgRibbons WeDonNeedNoSteenkgRibbons is offline Peculiar Outlook VBA item, Application_Quit Windows XP Peculiar Outlook VBA item, Application_Quit Office 2003
Novice
Peculiar Outlook VBA item, Application_Quit
 
Join Date: Jul 2014
Posts: 23
WeDonNeedNoSteenkgRibbons is on a distinguished road
Default

Thank you. I don't know where it explicitly says you can't stop Quit but I believe you.

The idea is not to "hit send" for drafts in progress, which is what most people seem to be interested in. Rathe, it's to impel me to either reply, delete, or act upon open messages that I received. E.g., boss sends me an email to make a plane reservation. I get distracted and it's now underneath 12 windows. I'm shutting down for the day and closing Outlook. The message is about to close and I may not notice it for a month. Instead, upon Quit, I'd like every open received email to confront me that they're still open (and possibly need action), rather than just silently closing, and allowing me to forget about them. It's because I effectively have a pseudo "to do list" of open messages I'd like to be confronted with as I go Quit.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook 'actions' menu item moved to the left? galgewater Outlook 0 07-30-2012 07:05 AM
How do I delete an Outlook appointment item with VBA? Joe Patrick Outlook 0 07-14-2011 06:56 AM
How to Delete Outlook Item with VBA Joe Patrick Outlook 0 07-14-2011 06:49 AM
How do you update existing Outlook calendar item from Word with macro? Joe Patrick Word VBA 0 07-09-2011 05:32 AM
Peculiar Outlook VBA item, Application_Quit Peculiar cell behavior markg2 Excel 7 05-28-2011 07:46 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:53 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