Hi Dears,
I have a similar problem and I 'd need help please:
I want to show a user form on closing the message which have two choices archive the message or delete it.
In this outlook session I add the next code:
Option Explicit
Public WithEvents colInspectors As Outlook.Inspectors
Public WithEvents objInspector As Outlook.Inspector
Private Sub Application_Startup()
'Call the subroutine to initialize the inspectors events
Init_colInspectorsEvent
End Sub
Private Sub Init_colInspectorsEvent()
'Initialize the inspectors events handler
Set colInspectors = Outlook.Inspectors
End Sub
Private Sub colInspectors_NewInspector(ByVal NewInspector As Inspector)
Set objInspector = NewInspector
End Sub
Private Sub objInspector_Close()
If objInspector.CurrentItem.Class = olMail Then
MsgBox "Mail inspector is closing"
Dim myForm As New UserForm1
myForm.Show
End If
End Sub
That means I want to show the userform on closing the message and it does work
and I have added the next code on the userform1 which has a button to make the delete of the message
Option Explicit
Private WithEvents m_Inspectors As Outlook.Inspectors
Private m_Mail As Outlook.MailItem
Private Sub Application_Startup()
Set m_Inspectors = Application.Inspectors
End Sub
Private Sub CommandButton1_Click()
'On Error Resume Next
If TypeOf Application.ActiveWindow Is Outlook.Explorer Then
Set m_Mail = Application.ActiveExplorer.Selection(1)
Else
Set m_Mail = Application.ActiveInspector.CurrentItem
m_Mail.Delete
Set m_Mail = Nothing
End If
Unload Me
End Sub
but unfortunately m_Mail.Delete doesn't work with error unable to complete the command could you advice please
> On Wednesday, May 02, 2007 4:38 AM Robi wrote:
> 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...?
>> On Wednesday, May 02, 2007 8:50 AM 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" <Robin@discussions.microsoft.com> wrote in message
>> news:7CD69FC7-F09E-4E98-A34E-DFE13187AFA6@microsoft.com...
>>> On Wednesday, May 02, 2007 9:21 AM Robi 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:
>>>> On Thursday, May 03, 2007 5:30 AM Robi wrote:
>>>> 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:
>>>>> On Thursday, May 03, 2007 8:58 AM 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" <Robin@discussions.microsoft.com> wrote in message
>>>>> news:E07896C1-7AD4-401B-AAD3-1ECA08EED004@microsoft.com...
>>>>>> On Thursday, May 03, 2007 9:11 AM Robi wrote:
>>>>>> Thanks Ken. It works fine wih the non-Wordmail option. Much appreciated.
>>>>>>
>>>>>> "Ken Slovak - [MVP - Outlook]" wrote:
>>>>>>> On Thursday, May 17, 2007 9:52 AM Robi 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:
>>>>>>>> On Tuesday, May 22, 2007 8:49 AM Robi wrote:
>>>>>>>> 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:
>>>>>>>>> On Wednesday, May 23, 2007 6:02 PM 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" <Robin@discussions.microsoft.com> wrote in message
>>>>>>>>> news:F965C618-8C4A-4D0B-9873-5559CF231FD4@microsoft.com...
>>>>>>>>>> On Wednesday, December 05, 2007 8:39 AM Robi wrote:
>>>>>>>>>> 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:
>>>>>>>>>>> On Wednesday, December 05, 2007 9:03 AM Ken Slovak - [MVP - Outlook] wrote:
>>>>>>>>>>> This is a VBA user form? If so there is no hWnd property exposed. You have
>>>>>>>>>>> to get the hWnd using the Win32 API function FindWindow().
>>>>>>>>>>>
>>>>>>>>>>> FindWindow() takes 2 arguments: window class and caption. You can leave the
>>>>>>>>>>> window class as a null string or you can use a tool like Spy++ to get the
>>>>>>>>>>> class name when a UserForm is being displayed. The caption would be whatever
>>>>>>>>>>> you set it to. After that you use the hWnd that you got for the other calls.
>>>>>>>>>>> hWnd would be a 32-bit unsigned integer, in VBA terms a Long.
>>>>>>>>>>>
>>>>>>>>>>> --
>>>>>>>>>>> Ken Slovak
>>>>>>>>>>> [MVP - Outlook]
>>>>>>>>>>>
http://www.slovaktech.com
>>>>>>>>>>> Author: Professional Programming Outlook 2007
>>>>>>>>>>> Reminder Manager, Extended Reminders, Attachment Options
>>>>>>>>>>>
http://www.slovaktech.com/products.htm
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> "Robin" <Robin@discussions.microsoft.com> wrote in message
>>>>>>>>>>> news:8F584137-216C-40FA-86CD-8AD1302BAAC4@microsoft.com...
>>>>>>>>>>>> On Thursday, December 06, 2007 3:55 AM Robi wrote:
>>>>>>>>>>>> hi Ken. Thanks for your comments. I am trying the FindWindow with ShowWindow
>>>>>>>>>>>> functions - not sure if you think it will work. "ShowWindow window, 5" should
>>>>>>>>>>>> in theory show UserForm1 unless I am mistaken. My syntax seems to be killing
>>>>>>>>>>>> me though (because I am a hacking a bit, as you can tell). I get "invalid use
>>>>>>>>>>>> of string" with NULL or "bad dll calling convention" with vbNullString. Am
>>>>>>>>>>>> also not sure if UserForm1 should be in qoutes. Am struggling to get past
>>>>>>>>>>>> this point. Can you help?
>>>>>>>>>>>>
>>>>>>>>>>>> Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
>>>>>>>>>>>> lpClassName As String, ByVal lpWindowName As String)
>>>>>>>>>>>> Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal
>>>>>>>>>>>> nCmdShow As Long)
>>>>>>>>>>>>
>>>>>>>>>>>> Public 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
>>>>>>>>>>>> Dim dlg As UserForm1
>>>>>>>>>>>> Dim window As Long
>>>>>>>>>>>>
>>>>>>>>>>>> If Item.Class = olMail Then
>>>>>>>>>>>> Set dlg = New UserForm1
>>>>>>>>>>>> dlg.answer = 0
>>>>>>>>>>>> dlg.Show ' display the userform
>>>>>>>>>>>>
>>>>>>>>>>>> window = FindWindow(Null, "UserForm1")
>>>>>>>>>>>> ShowWindow window, 5
>>>>>>>>>>>>
>>>>>>>>>>>> If dlg.answer = 1 Then
>>>>>>>>>>>> etc
>>>>>>>>>>>>
>>>>>>>>>>>> "Ken Slovak - [MVP - Outlook]" wrote:
>>>>>>>>>>>>> On Thursday, December 06, 2007 9:43 AM Ken Slovak - [MVP - Outlook] wrote:
>>>>>>>>>>>>> Both arguments are string values for FindWindow(). If you don't want to
>>>>>>>>>>>>> supply a caption or class name you would use "" as the argument. In this
>>>>>>>>>>>>> case for a UserForm you would use this:
>>>>>>>>>>>>>
>>>>>>>>>>>>> className = "ThunderDFrame"
>>>>>>>>>>>>> caption = "form caption, whatever it is"
>>>>>>>>>>>>>
>>>>>>>>>>>>> I made a quickie user form with a caption of "Foobar" so my call would be:
>>>>>>>>>>>>>
>>>>>>>>>>>>> caption = "Foobar"
>>>>>>>>>>>>> hWnd = FindWindow(className, caption)
>>>>>>>>>>>>>
>>>>>>>>>>>>> or for a null for the class name:
>>>>>>>>>>>>>
>>>>>>>>>>>>> hWnd = FindWindow("", caption)
>>>>>>>>>>>>>
>>>>>>>>>>>>> I got className = "ThunderDFrame" by displaying the user form and then
>>>>>>>>>>>>> looking at the open windows in Spy++.
>>>>>>>>>>>>>
>>>>>>>>>>>>> However, one problem with this is that userForm.Show() displays the user
>>>>>>>>>>>>> form modally by default so any code after that Show() line wouldn't execute
>>>>>>>>>>>>> until the user form was closed unless you explicitly show the form
>>>>>>>>>>>>> non-modally. So the call would have to be:
>>>>>>>>>>>>> userForm.Show vbModeless
>>>>>>>>>>>>>
>>>>>>>>>>>>> Then your FindWindow() code would be called when the window (user form) is
>>>>>>>>>>>>> still open. Of course then you have to do something to let the form work and
>>>>>>>>>>>>> stop continued execution of your code until the form is closed, something
>>>>>>>>>>>>> like a loop looking for a global Boolean flag that's set by the form when
>>>>>>>>>>>>> it's closing and is cleared by your calling code just before the form is
>>>>>>>>>>>>> opened.
>>>>>>>>>>>>>
>>>>>>>>>>>>> I'm not sure why you'd want to call ShowWindow with an argument of SW_SHOW
>>>>>>>>>>>>> after having already opened the window with UserForm.Show? Is there a
>>>>>>>>>>>>> specific reason for that?
>>>>>>>>>>>>>
>>>>>>>>>>>>> --
>>>>>>>>>>>>> Ken Slovak
>>>>>>>>>>>>> [MVP - Outlook]
>>>>>>>>>>>>>
http://www.slovaktech.com
>>>>>>>>>>>>> Author: Professional Programming Outlook 2007
>>>>>>>>>>>>> Reminder Manager, Extended Reminders, Attachment Options
>>>>>>>>>>>>>
http://www.slovaktech.com/products.htm
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> "Robin" <Robin@discussions.microsoft.com> wrote in message
>>>>>>>>>>>>> news:45B08195-D332-47F3-81D7-7CE531E7259A@microsoft.com...
>>>>>>>>>>>>>> On Friday, December 07, 2007 2:57 AM Robi wrote:
>>>>>>>>>>>>>> Hi Ken
>>>>>>>>>>>>>> I think I have cracked it, although I don't think I could tell you how
>>>>>>>>>>>>>> (probably just ended up confusing Outlook into submission). Not for the
>>>>>>>>>>>>>> fainthearted. Anyway, thanks a ton for your help.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> FOR THE COMMANDBUTTON FROM THE USERFORM:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Public answer As Integer
>>>>>>>>>>>>>> Public hWnd As Long
>>>>>>>>>>>>>> Public HWND_TOPMOST As Integer
>>>>>>>>>>>>>> Public SWP_NOSIZE As Integer
>>>>>>>>>>>>>> Public SWP_NOMOVE As Integer
>>>>>>>>>>>>>> Public SWP_NOACTIVATE As Integer
>>>>>>>>>>>>>> Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
>>>>>>>>>>>>>> lpClassName As String, ByVal lpWindowName As String) As Long
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Private Sub CommandButton2_Click()
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> hWnd = FindWindow(vbNullString, "UserForm1")
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> answer = 1
>>>>>>>>>>>>>> Me.Hide
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> End Sub
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> IN THE MODULE:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Public HWND_TOPMOST As Integer
>>>>>>>>>>>>>> Public SWP_NOSIZE As Integer
>>>>>>>>>>>>>> Public SWP_NOMOVE As Integer
>>>>>>>>>>>>>> Public SWP_NOACTIVATE As Integer
>>>>>>>>>>>>>> Private Declare Function SetWindowPos Lib "user32" (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) As Long
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Public 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
>>>>>>>>>>>>>> Dim dlg As UserForm1
>>>>>>>>>>>>>> Dim temp As Long
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> HWND_TOPMOST = -1
>>>>>>>>>>>>>> SWP_NOSIZE = &H1
>>>>>>>>>>>>>> SWP_NOMOVE = &H2
>>>>>>>>>>>>>> SWP_NOACTIVATE = &H10
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> If Item.Class = olMail Then
>>>>>>>>>>>>>> Set dlg = New UserForm1
>>>>>>>>>>>>>> dlg.answer = 0
>>>>>>>>>>>>>> dlg.Show vbModeless
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> temp = SetWindowPos(dlg.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or
>>>>>>>>>>>>>> SWP_NOMOVE Or SWP_NOACTIVATE)
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> dlg.Hide
>>>>>>>>>>>>>> dlg.Show vbModal
>>>>>>>>>>>>>> dlg.Hide
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> If dlg.answer = 1 Then
>>>>>>>>>>>>>> etc
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> "Ken Slovak - [MVP - Outlook]" wrote:
>>>>>>>>>>>>>>> On Friday, December 07, 2007 9:37 AM Ken Slovak - [MVP - Outlook] wrote:
>>>>>>>>>>>>>>> I'm glad it's working for you but the code doesn't make sense to me.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> In the module code you're showing the user form non-modally, then using
>>>>>>>>>>>>>>> dlg.hWnd in SetWindowPos. Since a user form has no hWnd you aren't passing a
>>>>>>>>>>>>>>> valid hWnd to SetWindowPos. You should be using FindWindow just after you
>>>>>>>>>>>>>>> show the user form to get the hWnd at that point, then pass that to
>>>>>>>>>>>>>>> SetWindowPos.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Then after you show the user form modally you hide it. You do realize that
>>>>>>>>>>>>>>> the line "dlg.Hide" won't be executed until the user form is closed, right?
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> I'd also be hesitant about using HWND_TOPMOST with SetWindowPos, that makes
>>>>>>>>>>>>>>> the form topmost even when other applications are switched to. So if say
>>>>>>>>>>>>>>> Word is also running, or IE, switching to that app in the task bar would
>>>>>>>>>>>>>>> still leave the user form on top, thereby annoying users. I'd be inclined to
>>>>>>>>>>>>>>> be using SetWindowLong there instead SetWindowPos or using SetWindowLong in
>>>>>>>>>>>>>>> addition to SetWindowPos with a HWND_TOP argument instead of HWND_TOPMOST.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> I'd also probably be using the class argument with FindWindow, that way in
>>>>>>>>>>>>>>> case there happen to be 2 windows showing with the same caption you are sure
>>>>>>>>>>>>>>> that you're finding the user form window and not some other one.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> --
>>>>>>>>>>>>>>> Ken Slovak
>>>>>>>>>>>>>>> [MVP - Outlook]
>>>>>>>>>>>>>>>
http://www.slovaktech.com
>>>>>>>>>>>>>>> Author: Professional Programming Outlook 2007
>>>>>>>>>>>>>>> Reminder Manager, Extended Reminders, Attachment Options
>>>>>>>>>>>>>>>
http://www.slovaktech.com/products.htm
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> "Robin" <Robin@discussions.microsoft.com> wrote in message
>>>>>>>>>>>>>>> news:0ED95781-1766-48DC-888F-943496FF9345@microsoft.com...
>>>>>>>>>>>>>>>> On Tuesday, May 20, 2008 12:28 AM MDSouz wrote:
>>>>>>>>>>>>>>>> Hi I am trying to something similar only instead of saving the reply I would
>>>>>>>>>>>>>>>> like it to delete the original message from the inbox. Is this doable?
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> "Robin" wrote:
>>>>>>>>>>>>>>>>> On Wednesday, May 21, 2008 11:27 AM <elegaultZZ wrote:
>>>>>>>>>>>>>>>>> Yes, that is quite possible. You can trap the MailItem's Send event and
>>>>>>>>>>>>>>>>> throw your dialog there. The ActiveExplorer.Selection object should contain
>>>>>>>>>>>>>>>>> a reference to the message that is being replied to, or one of the messages
>>>>>>>>>>>>>>>>> in the Application.Inspectors collection. In either situation, you can loop
>>>>>>>>>>>>>>>>> through the collection and compare the Subject property with the current
>>>>>>>>>>>>>>>>> reply message.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> --
>>>>>>>>>>>>>>>>> Eric Legault [MVP - Outlook]
>>>>>>>>>>>>>>>>> MCDBA, MCTS (Messaging & Collaboration, SharePoint Infrastructure, MOSS 2007
>>>>>>>>>>>>>>>>> & WSS 3.0 Application Development)
>>>>>>>>>>>>>>>>> Collaborative Innovations
>>>>>>>>>>>>>>>>> -> Try Picture Attachments Wizard For Microsoft Outlook <-
>>>>>>>>>>>>>>>>> Web:
http://www.collaborativeinnovations.ca
>>>>>>>>>>>>>>>>> Blog:
http://blogs.officezealot.com/legault
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> "M.D'Souza" <MDSouza@discussions.microsoft.com> wrote in message
>>>>>>>>>>>>>>>>> news:FCBE765C-DCB5-4923-ABC9-1FDFAA53F581@microsoft.com...
>>>>>>>>>>>>>>>>>> On Wednesday, June 22, 2011 3:08 AM Samira Programmer wrote:
>>>>>>>>>>>>>>>>>> Hi Dears,
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> I have a similar problem and I 'd need help please:
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> I want to show a user form on closing the message which have two choices archive the message or delete it.
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> In this outlook session I add the next code:
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Option Explicit
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Public WithEvents colInspectors As Outlook.Inspectors
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Public WithEvents objInspector As Outlook.Inspector
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Private Sub Application_Startup()
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> 'Call the subroutine to initialize the inspectors events
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Init_colInspectorsEvent
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> End Sub
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Private Sub Init_colInspectorsEvent()
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> 'Initialize the inspectors events handler
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Set colInspectors = Outlook.Inspectors
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> End Sub
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Private Sub colInspectors_NewInspector(ByVal NewInspector As Inspector)
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Set objInspector = NewInspector
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> End Sub
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Private Sub objInspector_Close()
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> If objInspector.CurrentItem.Class = olMail Then
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> MsgBox "Mail inspector is closing"
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Dim myForm As New UserForm1
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> myForm.Show
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> End If
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> End Sub
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> That means I want to show the userform on closing the message and it does work
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> and I have added the next code on the userform1 which has a button to make the delete of the message
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Option Explicit
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Private WithEvents m_Inspectors As Outlook.Inspectors
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Private m_Mail As Outlook.MailItem
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Private Sub Application_Startup()
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Set m_Inspectors = Application.Inspectors
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> End Sub
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Private Sub CommandButton1_Click()
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> 'On Error Resume Next
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> If TypeOf Application.ActiveWindow Is Outlook.Explorer Then
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Set m_Mail = Application.ActiveExplorer.Selection(1)
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Else
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Set m_Mail = Application.ActiveInspector.CurrentItem
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> m_Mail.Delete
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Set m_Mail = Nothing
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> End If
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> Unload Me
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> End Sub
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>> but unfortunately m_Mail.Delete doesn't work with error unable to complete the command could you advice please