![]() |
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. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
#11
|
|||
|
|||
![]()
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" wrote in message ... 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 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... |
Ads |
#12
|
|||
|
|||
![]()
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: 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" wrote in message ... 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 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... |
#13
|
|||
|
|||
![]()
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" wrote in message ... 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 |
#14
|
|||
|
|||
![]()
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: 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" wrote in message ... 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 |
#15
|
|||
|
|||
![]()
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" wrote in message ... 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 |
#16
|
|||
|
|||
![]()
Hi I'm 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: 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...? |
#17
|
|||
|
|||
![]()
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" wrote in message ... Hi I'm 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: 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...? |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Custom action | Ian | Outlook - General Queries | 9 | April 23rd 07 09:05 PM |
Save while sending email in Outlook | Marc C | Outlook and VBA | 1 | December 19th 06 06:55 PM |
Custom Action DLL with VB? | Menachem Bazian | Outlook - General Queries | 4 | August 18th 06 01:58 AM |
Outlook 2003 Custom Action on Outgoing Email Rules | Pankaj | Outlook and VBA | 1 | June 25th 06 09:35 AM |
custom action | adubb | Outlook - Using Forms | 1 | March 30th 06 08:17 PM |