A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

custom action: save or delete email after sending



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old May 2nd 07, 10:38 AM posted to microsoft.public.outlook.program_vba
robin
external usenet poster
 
Posts: 53
Default custom action: save or delete email after sending

Hi. I would like to create a custom action that pops up a message box on
sending an email. This will ask me whether I would like this saved to my sent
items folder or not. This will make organising my sent items much easier
later on. Any ideas...?
Ads
  #2  
Old May 2nd 07, 02:50 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default custom action: save or delete email after sending

A better solution would be to use an Application_ItemSend event handler that
will fire every time an item is sent and show a message box asking whether
to save to Sent Items and if the answer is no to set the DeleteAfterSubmit
Boolean property to True.

If macros are enabled and this code is in ThisOutlookSession you will have
what you want, but I'd think it would get annoying after a while to be
prompted after sending every email.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim answer As Long

If Item.Class = olMail Then
answer = MsgBox("Do you want to save this email: " & _
Item.Subject & " to Sent Items?", vbYesNo)

If answer = vbNo Then
Item.DeleteAfterSubmit = True
End If
End If
End Sub


--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Robin" wrote in message
...
Hi. I would like to create a custom action that pops up a message box on
sending an email. This will ask me whether I would like this saved to my
sent
items folder or not. This will make organising my sent items much easier
later on. Any ideas...?


  #3  
Old May 2nd 07, 03:21 PM posted to microsoft.public.outlook.program_vba
robin
external usenet poster
 
Posts: 53
Default custom action: save or delete email after sending

That's perfect thanks. I know this might result in a small amount of pain,
but I am sure it will be worth it when it comes to organising my sent emails.
A bells and whistles version of this would be a form which pops up after
sending an email which shows my outlook folders and asks me to which folder I
want file the sent email with a "DELETE EMAIL" as the top option. Painful I
know but I will have to do this some time anyway...
Cheers.

"Ken Slovak - [MVP - Outlook]" wrote:

A better solution would be to use an Application_ItemSend event handler that
will fire every time an item is sent and show a message box asking whether
to save to Sent Items and if the answer is no to set the DeleteAfterSubmit
Boolean property to True.

If macros are enabled and this code is in ThisOutlookSession you will have
what you want, but I'd think it would get annoying after a while to be
prompted after sending every email.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim answer As Long

If Item.Class = olMail Then
answer = MsgBox("Do you want to save this email: " & _
Item.Subject & " to Sent Items?", vbYesNo)

If answer = vbNo Then
Item.DeleteAfterSubmit = True
End If
End If
End Sub


--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Robin" wrote in message
...
Hi. I would like to create a custom action that pops up a message box on
sending an email. This will ask me whether I would like this saved to my
sent
items folder or not. This will make organising my sent items much easier
later on. Any ideas...?



  #4  
Old May 3rd 07, 11:30 AM posted to microsoft.public.outlook.program_vba
robin
external usenet poster
 
Posts: 53
Default custom action: save or delete email after sending

Sorry, one little snag. When I click on send, the PC freezes. I have to click
on the Microsoft Outlook tab on the taskbar which brings the message box to
the front and then select YES/NO. Any ideas on how to solve this (minimise
current window?)
Thanks again

"Robin" wrote:

That's perfect thanks. I know this might result in a small amount of pain,
but I am sure it will be worth it when it comes to organising my sent emails.
A bells and whistles version of this would be a form which pops up after
sending an email which shows my outlook folders and asks me to which folder I
want file the sent email with a "DELETE EMAIL" as the top option. Painful I
know but I will have to do this some time anyway...
Cheers.

"Ken Slovak - [MVP - Outlook]" wrote:

A better solution would be to use an Application_ItemSend event handler that
will fire every time an item is sent and show a message box asking whether
to save to Sent Items and if the answer is no to set the DeleteAfterSubmit
Boolean property to True.

If macros are enabled and this code is in ThisOutlookSession you will have
what you want, but I'd think it would get annoying after a while to be
prompted after sending every email.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim answer As Long

If Item.Class = olMail Then
answer = MsgBox("Do you want to save this email: " & _
Item.Subject & " to Sent Items?", vbYesNo)

If answer = vbNo Then
Item.DeleteAfterSubmit = True
End If
End If
End Sub


--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Robin" wrote in message
...
Hi. I would like to create a custom action that pops up a message box on
sending an email. This will ask me whether I would like this saved to my
sent
items folder or not. This will make organising my sent items much easier
later on. Any ideas...?



  #5  
Old May 3rd 07, 02:58 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default custom action: save or delete email after sending

Using WordMail, correct? That's a problem. Word is being subclassed by
Outlook and WordMail items are a weird mix of in and out of process threads.
The bottom line is that the parent window of the message box is most likely
the Outlook Explorer window and not the WordMail window.

The best way to fix that is to display a dialog box non-modally, get its
hWnd and use that in a call to SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOSIZE + SWP_NOMOVE). After that call to set your dialog on top of all
other windows you can then make the dialog modal.

An easier alternative that doesn't involve hacks with Win32 API calls would
be to not use WordMail.

If you decide to use the hack approach all those consts and the declaration
for SetWindowPos are in the MSDN library.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Robin" wrote in message
...
Sorry, one little snag. When I click on send, the PC freezes. I have to
click
on the Microsoft Outlook tab on the taskbar which brings the message box
to
the front and then select YES/NO. Any ideas on how to solve this (minimise
current window?)
Thanks again


  #6  
Old May 3rd 07, 03:11 PM posted to microsoft.public.outlook.program_vba
robin
external usenet poster
 
Posts: 53
Default custom action: save or delete email after sending

Thanks Ken. It works fine wih the non-Wordmail option. Much appreciated.

"Ken Slovak - [MVP - Outlook]" wrote:

Using WordMail, correct? That's a problem. Word is being subclassed by
Outlook and WordMail items are a weird mix of in and out of process threads.
The bottom line is that the parent window of the message box is most likely
the Outlook Explorer window and not the WordMail window.

The best way to fix that is to display a dialog box non-modally, get its
hWnd and use that in a call to SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOSIZE + SWP_NOMOVE). After that call to set your dialog on top of all
other windows you can then make the dialog modal.

An easier alternative that doesn't involve hacks with Win32 API calls would
be to not use WordMail.

If you decide to use the hack approach all those consts and the declaration
for SetWindowPos are in the MSDN library.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Robin" wrote in message
...
Sorry, one little snag. When I click on send, the PC freezes. I have to
click
on the Microsoft Outlook tab on the taskbar which brings the message box
to
the front and then select YES/NO. Any ideas on how to solve this (minimise
current window?)
Thanks again



  #7  
Old May 17th 07, 03:52 PM posted to microsoft.public.outlook.program_vba
robin
external usenet poster
 
Posts: 53
Default custom action: save or delete email after sending

Hi. If you add "+ vbSystemModal" to the MsgBox statement, it works ok with MS
Word as the editor. The email closes and then you can see the message box
which is fine (before, the email froze after sending).

"Robin" wrote:

Thanks Ken. It works fine wih the non-Wordmail option. Much appreciated.

"Ken Slovak - [MVP - Outlook]" wrote:

Using WordMail, correct? That's a problem. Word is being subclassed by
Outlook and WordMail items are a weird mix of in and out of process threads.
The bottom line is that the parent window of the message box is most likely
the Outlook Explorer window and not the WordMail window.

The best way to fix that is to display a dialog box non-modally, get its
hWnd and use that in a call to SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOSIZE + SWP_NOMOVE). After that call to set your dialog on top of all
other windows you can then make the dialog modal.

An easier alternative that doesn't involve hacks with Win32 API calls would
be to not use WordMail.

If you decide to use the hack approach all those consts and the declaration
for SetWindowPos are in the MSDN library.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Robin" wrote in message
...
Sorry, one little snag. When I click on send, the PC freezes. I have to
click
on the Microsoft Outlook tab on the taskbar which brings the message box
to
the front and then select YES/NO. Any ideas on how to solve this (minimise
current window?)
Thanks again



  #8  
Old May 22nd 07, 02:49 PM posted to microsoft.public.outlook.program_vba
robin
external usenet poster
 
Posts: 53
Default custom action: save or delete email after sending

Oops. it seems freezing still happens, depending on what is open at the time.
So I am trying to get the other API hack that you suggested working. Just to
check, I currently use a standard Msgbox statement, but in order to get its
hwnd, do I need to create a new form instead (that looks exactly like a
msgbox) and then use the statement SetWindowPos(Form1.hwnd, HWND_TOPMOST, 0,
0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE) or is there a way of getting the hwnd of a
standard msgbox?
Thanks a lot.

"Robin" wrote:

Hi. If you add "+ vbSystemModal" to the MsgBox statement, it works ok with MS
Word as the editor. The email closes and then you can see the message box
which is fine (before, the email froze after sending).

"Robin" wrote:

Thanks Ken. It works fine wih the non-Wordmail option. Much appreciated.

"Ken Slovak - [MVP - Outlook]" wrote:

Using WordMail, correct? That's a problem. Word is being subclassed by
Outlook and WordMail items are a weird mix of in and out of process threads.
The bottom line is that the parent window of the message box is most likely
the Outlook Explorer window and not the WordMail window.

The best way to fix that is to display a dialog box non-modally, get its
hWnd and use that in a call to SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOSIZE + SWP_NOMOVE). After that call to set your dialog on top of all
other windows you can then make the dialog modal.

An easier alternative that doesn't involve hacks with Win32 API calls would
be to not use WordMail.

If you decide to use the hack approach all those consts and the declaration
for SetWindowPos are in the MSDN library.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Robin" wrote in message
...
Sorry, one little snag. When I click on send, the PC freezes. I have to
click
on the Microsoft Outlook tab on the taskbar which brings the message box
to
the front and then select YES/NO. Any ideas on how to solve this (minimise
current window?)
Thanks again


  #9  
Old May 24th 07, 12:02 AM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default custom action: save or delete email after sending

I personally don't like to try to control a MsgBox that way. I prefer to
create an equivalent form and open it non-modally. I then set it to the top
and make it modal in the Activate event of the form. That will work even
with WordMail if you get the right window handle.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Robin" wrote in message
...
Oops. it seems freezing still happens, depending on what is open at the
time.
So I am trying to get the other API hack that you suggested working. Just
to
check, I currently use a standard Msgbox statement, but in order to get
its
hwnd, do I need to create a new form instead (that looks exactly like a
msgbox) and then use the statement SetWindowPos(Form1.hwnd, HWND_TOPMOST,
0,
0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE) or is there a way of getting the hwnd
of a
standard msgbox?
Thanks a lot.


  #10  
Old December 5th 07, 02:39 PM posted to microsoft.public.outlook.program_vba
robin
external usenet poster
 
Posts: 53
Default custom action: save or delete email after sending

Hi Ken
I have come back this and am still struggling. I am struggling to get the
hWnd for the UserForm. (error: compile error, method or data member not
found). I am struggling to get anything on the internet. The code so far:

Public HWND_TOPMOST As Integer
Public SWP_NOSIZE
Public SWP_NOMOVE
Public SWP_NOACTIVATE

Private Declare Sub setWindowPos Lib "User" (ByVal hWnd As Long, ByVal
hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long,
ByVal cy As Long, ByVal wFlags As Long)

Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim objFolder As Outlook.MAPIFolder
Dim oSent As Outlook.MAPIFolder
Dim objNS As Outlook.NameSpace

WND_TOPMOST = -1
SWP_NOSIZE = &H1
SWP_NOMOVE = &H2
SWP_NOACTIVATE = &H10

If Item.Class = olMail Then
UserForm1.Show
Call setWindowPos(UserForm1.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE
Or SWP_NOMOVE Or SWP_NOACTIVATE)
If answer = "No" Then 'No from UserForm1, I do not want to save the email

On Error Resume Next
Set objNS = Application.GetNamespace("MAPI")
Set oSent = objNS.GetDefaultFolder(olFolderSentMail)
Set objFolder = oSent.Folders("Temp Sent") 'Assume this is a mail
folder

If objFolder Is Nothing Then
MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation,
"INVALID FOLDER"
End If

If Application.ActiveInspector Is Nothing Then 'Require that this
procedure be called for an open item
Exit Sub
End If

If Application.ActiveInspector.CurrentItem.Class olMail Then
Exit Sub
End If

Set Item.SaveSentMessageFolder = objFolder

Set objFolder = Nothing
Set oSent = Nothing
Set objNS = Nothing

End If
End If

End Sub

Your help would be greatly appreciated...

"Ken Slovak - [MVP - Outlook]" wrote:

I personally don't like to try to control a MsgBox that way. I prefer to
create an equivalent form and open it non-modally. I then set it to the top
and make it modal in the Activate event of the form. That will work even
with WordMail if you get the right window handle.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Robin" wrote in message
...
Oops. it seems freezing still happens, depending on what is open at the
time.
So I am trying to get the other API hack that you suggested working. Just
to
check, I currently use a standard Msgbox statement, but in order to get
its
hwnd, do I need to create a new form instead (that looks exactly like a
msgbox) and then use the statement SetWindowPos(Form1.hwnd, HWND_TOPMOST,
0,
0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE) or is there a way of getting the hwnd
of a
standard msgbox?
Thanks a lot.



 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom action Ian Outlook - General Queries 9 April 23rd 07 10:05 PM
Save while sending email in Outlook Marc C Outlook and VBA 1 December 19th 06 07:55 PM
Custom Action DLL with VB? Menachem Bazian Outlook - General Queries 4 August 18th 06 02:58 AM
Outlook 2003 Custom Action on Outgoing Email Rules Pankaj Outlook and VBA 1 June 25th 06 10:35 AM
custom action adubb Outlook - Using Forms 1 March 30th 06 09:17 PM


All times are GMT +1. The time now is 08:52 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.