![]() |
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 |
|
#1
|
|||
|
|||
![]()
Outlook 2003
I have found and edited the following code (sourced from Sue Mosher) and assigned it to a button on a customised tool bar but would prefer to have this run when I click on the 'new mail message' button on the standard tool bar. Is this possible? Sub CreateNewMail() 'Creates a new e-mail item Dim olApp As Outlook.Application Dim objMail As Outlook.MailItem Dim strEmail As String 'Set Application Set olApp = Outlook.Application 'Set new email item Set objMail = olApp.CreateItem(olMailItem) 'Ask user to record project number strEmail = InputBox("Please enter Job Number or Client Name", _ "Job Number") 'Set Job Number in BC objMail.CC = strEmail 'Display the email objMail.Display 'Resolve project number to find project address objMail.Recipients.ResolveAll End Sub Also the way I am using the 'resolve' does not seem to work. The project address is not resolved until I hot the send button. This is no big issue but I if someone could help I would prefer to check the project number and find the correct address before I hit the send button. Thanks Carmi |
#2
|
|||
|
|||
![]()
Instead of trapping clicks on the Send button, it would be better to trap
additions to the Inspectors collection. See my blog post he Getting a Handle on Your E-mails with VBA: http://blogs.officezealot.com/legaul...cles/2224.aspx New e-mails can be created by shortcut keys and other methods, so relying on a button click won't catch all of the situations. Try resolving during Item_Send, and cancelling the event if an address is invalid. -- Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "Carmi" wrote: Outlook 2003 I have found and edited the following code (sourced from Sue Mosher) and assigned it to a button on a customised tool bar but would prefer to have this run when I click on the 'new mail message' button on the standard tool bar. Is this possible? Sub CreateNewMail() 'Creates a new e-mail item Dim olApp As Outlook.Application Dim objMail As Outlook.MailItem Dim strEmail As String 'Set Application Set olApp = Outlook.Application 'Set new email item Set objMail = olApp.CreateItem(olMailItem) 'Ask user to record project number strEmail = InputBox("Please enter Job Number or Client Name", _ "Job Number") 'Set Job Number in BC objMail.CC = strEmail 'Display the email objMail.Display 'Resolve project number to find project address objMail.Recipients.ResolveAll End Sub Also the way I am using the 'resolve' does not seem to work. The project address is not resolved until I hot the send button. This is no big issue but I if someone could help I would prefer to check the project number and find the correct address before I hit the send button. Thanks Carmi |
#3
|
|||
|
|||
![]()
Dear Eric - firstly thank you for your help and pointing me to your blog. It
was very helpful as it is written in a way that makes it very easy to understand (especially the parts about the This OutlookSession and the Class Module). In all honesty I dont think I fully understand the code related to Inspector Object all that well but the code works!... well nearly. I do have a follow on question relating to a discussion between yourself and Nick on the same blog (1/18/2005 9:06am) concerning the different olMail events. The (very simple) question is; What is the event to trap for the creation of a new mail message? I understand, and can find, the appropriate references for using a objMailItem_Forward or objMailItem_Reply events but for the life of me cant find one for creating a new message. Any direction would be greatly appreciated Carmi "Eric Legault [MVP - Outlook]" wrote: Instead of trapping clicks on the Send button, it would be better to trap additions to the Inspectors collection. See my blog post he Getting a Handle on Your E-mails with VBA: http://blogs.officezealot.com/legaul...cles/2224.aspx New e-mails can be created by shortcut keys and other methods, so relying on a button click won't catch all of the situations. Try resolving during Item_Send, and cancelling the event if an address is invalid. -- Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "Carmi" wrote: Outlook 2003 I have found and edited the following code (sourced from Sue Mosher) and assigned it to a button on a customised tool bar but would prefer to have this run when I click on the 'new mail message' button on the standard tool bar. Is this possible? Sub CreateNewMail() 'Creates a new e-mail item Dim olApp As Outlook.Application Dim objMail As Outlook.MailItem Dim strEmail As String 'Set Application Set olApp = Outlook.Application 'Set new email item Set objMail = olApp.CreateItem(olMailItem) 'Ask user to record project number strEmail = InputBox("Please enter Job Number or Client Name", _ "Job Number") 'Set Job Number in BC objMail.CC = strEmail 'Display the email objMail.Display 'Resolve project number to find project address objMail.Recipients.ResolveAll End Sub Also the way I am using the 'resolve' does not seem to work. The project address is not resolved until I hot the send button. This is no big issue but I if someone could help I would prefer to check the project number and find the correct address before I hit the send button. Thanks Carmi |
#5
|
|||
|
|||
![]()
Regarding your previous post: The Inspectors_NewInspector event is the
essential thing to monitor to get a reference to any opened Outlook item, whether it is a new item or an existing one. For e-mails, once you have set a reference to a module-level MailItem object using the With Events keyword (as explained in my blog) you can then trap that item's specific events and put your code in the appropriate location. You've done this already in the Open event, so check there if the Sent property is False and you'll know that this is a new e-mail item. However, I'm having trouble understanding your issues with resolving. The best thing I can suggest is to get specific Recipient objects from the Recipients collection and call Recipient.Resolve for each one. You also cannot call the Check Names dialog manually unfortunately. -- Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "Carmi" wrote: Eric - following on from my last message I would also like to resolve the addresses when I create the mail based on the Name or number typed into the inputbox. My reason for this is because there can be a number of projects for the same client and I may not know what the Project number is. example Client Name = Akzo 3 separate email address relating to 3 different projects I changed my code to use the recipient.resolve which works only if their is a unique address. If there are potentially more than one addresses based on the information provided then the code as is does not work. My Current Code is as follows; Private Sub objMailItem_Open(Cancel As Boolean) Dim strEmail As String Dim objRecipient As Recipient Dim subject As String 'to be used later With objMailItem ‘My clumsy way of determining if it is a newly created message as I don’t know the ‘correct event to hook onto. If .To = "" And .subject = "" Then 'Input messagebox for Client Name or Project Number strEmail = InputBox("Please Input Appropriate Job Number or Client Name", _ "Job Number") 'If user does not want to send mail to project mailbox (eg Private) If strEmail = "" Then Exit Sub 'Use Project Number or Client Name as recipient address Set objRecipient = objMailItem.Recipients.Add(strEmail) 'Move recipient to CC field objRecipient.Type = olCC 'Resolve the address to find the correct Project email address eg objMailItem.Recipients.ResolveAll End If End With End Sub I want the resolve function to open the check names dialog box if there is more than one potential match so I can select the right address. I do not to wait until the message is sent for the check names dialog to appear as ultimately I want to use some of the properties associated with the project address to generate the subject line (i.e Auto Generate the Job Number and client name in the subject line…. That will be another post). Strangely enough I find that if there is more than one match the user input from the inputbox is displayed in the To field but when I hit send and select the correct address from Match Name that the correct address will be displayed in the CC. Any other suggestions on how to make better use of the code I have will also be most welcome. Sorry for the long post but I hope you can help. Thanks Carmi My Current Code is as follows; Private Sub objMailItem_Open(Cancel As Boolean) Dim strEmail As String Dim objRecipient As Recipient Dim subject As String 'to be used later With objMailItem If .To = "" And .subject = "" Then 'Input messagebox for Client Name or Project Number strEmail = InputBox("Please Input Appropriate Job Number or Client Name", _ "Job Number") 'If user does not want to send mail to project mailbox If strEmail = "" Then Exit Sub 'Use Project Number or Client Name as recipient address Set objRecipient = objMailItem.Recipients.Add(strEmail) 'Move recipient to CC field objRecipient.Type = olCC 'Resolve the address to find the correct Project email address eg If objMailItem.Recipients.ResolveAll = False Then MsgBox "Please click on Check Name" End If End If End With End Sub if there are options. Strangly if I use the Akzo example where there is more than one project email address resolve will do nothing and 'Akzo' will display in the "Carmi" wrote: Dear Eric - firstly thank you for your help and pointing me to your blog. It was very helpful as it is written in a way that makes it very easy to understand (especially the parts about the This OutlookSession and the Class Module). In all honesty I dont think I fully understand the code related to Inspector Object all that well but the code works!... well nearly. I do have a follow on question relating to a discussion between yourself and Nick on the same blog (1/18/2005 9:06am) concerning the different olMail events. The (very simple) question is; What is the event to trap for the creation of a new mail message? I understand, and can find, the appropriate references for using a objMailItem_Forward or objMailItem_Reply events but for the life of me cant find one for creating a new message. Any direction would be greatly appreciated Carmi "Eric Legault [MVP - Outlook]" wrote: Instead of trapping clicks on the Send button, it would be better to trap additions to the Inspectors collection. See my blog post he Getting a Handle on Your E-mails with VBA: http://blogs.officezealot.com/legaul...cles/2224.aspx New e-mails can be created by shortcut keys and other methods, so relying on a button click won't catch all of the situations. Try resolving during Item_Send, and cancelling the event if an address is invalid. -- Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "Carmi" wrote: Outlook 2003 I have found and edited the following code (sourced from Sue Mosher) and assigned it to a button on a customised tool bar but would prefer to have this run when I click on the 'new mail message' button on the standard tool bar. Is this possible? Sub CreateNewMail() 'Creates a new e-mail item Dim olApp As Outlook.Application Dim objMail As Outlook.MailItem Dim strEmail As String 'Set Application Set olApp = Outlook.Application 'Set new email item Set objMail = olApp.CreateItem(olMailItem) 'Ask user to record project number strEmail = InputBox("Please enter Job Number or Client Name", _ "Job Number") 'Set Job Number in BC objMail.CC = strEmail 'Display the email objMail.Display 'Resolve project number to find project address objMail.Recipients.ResolveAll End Sub Also the way I am using the 'resolve' does not seem to work. The project address is not resolved until I hot the send button. This is no big issue but I if someone could help I would prefer to check the project number and find the correct address before I hit the send button. Thanks Carmi |
#6
|
|||
|
|||
![]()
Dear Eric - firstly thanks again for your reply and your help - it is very
much appreciated. New Blank Email Conceptually I think I understand the Inspectors_NewInspector event and that you can trap an items specific events by monitoring this. However, what I don't understand is how to trap a newly created blank message (the same as clicking on the new message button on the standard tool bar). I have found the events for all the others in your blog and in the object browser (eg forward, reply, replyall) but can not find the line of code for a new Blank message. Simply put what is the event for a new blank message called? Private Sub objMailItem_newBlankMessage(Cancel As Boolean)? I used the open event and then the (If .To = "" And .subject = "" ) statement to select blank messages but to me this seems clumsy. Resolve Addresses The resolve address issue relates my requirement to be able to call the 'Check Names' dialog box prior to sending an email. There can be many matches for project email address to a client name and if the 'Check Name' dialog box can not be called using code then I can't select the right address. The reason I wanted to assign the correct address on creating a new message but before composing the body of the message was so I could use the display name of the address in the Subject field. Can you suggest any other method? Carmi "Eric Legault [MVP - Outlook]" wrote: Regarding your previous post: The Inspectors_NewInspector event is the essential thing to monitor to get a reference to any opened Outlook item, whether it is a new item or an existing one. For e-mails, once you have set a reference to a module-level MailItem object using the With Events keyword (as explained in my blog) you can then trap that item's specific events and put your code in the appropriate location. You've done this already in the Open event, so check there if the Sent property is False and you'll know that this is a new e-mail item. However, I'm having trouble understanding your issues with resolving. The best thing I can suggest is to get specific Recipient objects from the Recipients collection and call Recipient.Resolve for each one. You also cannot call the Check Names dialog manually unfortunately. -- Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "Carmi" wrote: Eric - following on from my last message I would also like to resolve the addresses when I create the mail based on the Name or number typed into the inputbox. My reason for this is because there can be a number of projects for the same client and I may not know what the Project number is. example Client Name = Akzo 3 separate email address relating to 3 different projects I changed my code to use the recipient.resolve which works only if their is a unique address. If there are potentially more than one addresses based on the information provided then the code as is does not work. My Current Code is as follows; Private Sub objMailItem_Open(Cancel As Boolean) Dim strEmail As String Dim objRecipient As Recipient Dim subject As String 'to be used later With objMailItem ‘My clumsy way of determining if it is a newly created message as I don’t know the ‘correct event to hook onto. If .To = "" And .subject = "" Then 'Input messagebox for Client Name or Project Number strEmail = InputBox("Please Input Appropriate Job Number or Client Name", _ "Job Number") 'If user does not want to send mail to project mailbox (eg Private) If strEmail = "" Then Exit Sub 'Use Project Number or Client Name as recipient address Set objRecipient = objMailItem.Recipients.Add(strEmail) 'Move recipient to CC field objRecipient.Type = olCC 'Resolve the address to find the correct Project email address eg objMailItem.Recipients.ResolveAll End If End With End Sub I want the resolve function to open the check names dialog box if there is more than one potential match so I can select the right address. I do not to wait until the message is sent for the check names dialog to appear as ultimately I want to use some of the properties associated with the project address to generate the subject line (i.e Auto Generate the Job Number and client name in the subject line…. That will be another post). Strangely enough I find that if there is more than one match the user input from the inputbox is displayed in the To field but when I hit send and select the correct address from Match Name that the correct address will be displayed in the CC. Any other suggestions on how to make better use of the code I have will also be most welcome. Sorry for the long post but I hope you can help. Thanks Carmi My Current Code is as follows; Private Sub objMailItem_Open(Cancel As Boolean) Dim strEmail As String Dim objRecipient As Recipient Dim subject As String 'to be used later With objMailItem If .To = "" And .subject = "" Then 'Input messagebox for Client Name or Project Number strEmail = InputBox("Please Input Appropriate Job Number or Client Name", _ "Job Number") 'If user does not want to send mail to project mailbox If strEmail = "" Then Exit Sub 'Use Project Number or Client Name as recipient address Set objRecipient = objMailItem.Recipients.Add(strEmail) 'Move recipient to CC field objRecipient.Type = olCC 'Resolve the address to find the correct Project email address eg If objMailItem.Recipients.ResolveAll = False Then MsgBox "Please click on Check Name" End If End If End With End Sub if there are options. Strangly if I use the Akzo example where there is more than one project email address resolve will do nothing and 'Akzo' will display in the "Carmi" wrote: Dear Eric - firstly thank you for your help and pointing me to your blog. It was very helpful as it is written in a way that makes it very easy to understand (especially the parts about the This OutlookSession and the Class Module). In all honesty I dont think I fully understand the code related to Inspector Object all that well but the code works!... well nearly. I do have a follow on question relating to a discussion between yourself and Nick on the same blog (1/18/2005 9:06am) concerning the different olMail events. The (very simple) question is; What is the event to trap for the creation of a new mail message? I understand, and can find, the appropriate references for using a objMailItem_Forward or objMailItem_Reply events but for the life of me cant find one for creating a new message. Any direction would be greatly appreciated Carmi "Eric Legault [MVP - Outlook]" wrote: Instead of trapping clicks on the Send button, it would be better to trap additions to the Inspectors collection. See my blog post he Getting a Handle on Your E-mails with VBA: http://blogs.officezealot.com/legaul...cles/2224.aspx New e-mails can be created by shortcut keys and other methods, so relying on a button click won't catch all of the situations. Try resolving during Item_Send, and cancelling the event if an address is invalid. -- Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "Carmi" wrote: Outlook 2003 I have found and edited the following code (sourced from Sue Mosher) and assigned it to a button on a customised tool bar but would prefer to have this run when I click on the 'new mail message' button on the standard tool bar. Is this possible? Sub CreateNewMail() 'Creates a new e-mail item Dim olApp As Outlook.Application Dim objMail As Outlook.MailItem Dim strEmail As String 'Set Application Set olApp = Outlook.Application 'Set new email item Set objMail = olApp.CreateItem(olMailItem) 'Ask user to record project number strEmail = InputBox("Please enter Job Number or Client Name", _ "Job Number") 'Set Job Number in BC objMail.CC = strEmail 'Display the email objMail.Display 'Resolve project number to find project address objMail.Recipients.ResolveAll End Sub Also the way I am using the 'resolve' does not seem to work. The project address is not resolved until I hot the send button. This is no big issue but I if someone could help I would prefer to check the project number and find the correct address before I hit the send button. Thanks Carmi |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Message Rule Does Not Run VBA Procedure | Lowell | Outlook and VBA | 18 | March 9th 06 06:47 PM |
Using VBA code to move current message to a folder | Dean | Outlook and VBA | 4 | February 26th 06 01:46 AM |
how to apply vba code to OL2003 forms ? | TimR | Outlook - Using Contacts | 1 | February 17th 06 04:41 PM |
Automatically trigger a VBA macro to run when connection to exchange server has been made. | [email protected] | Outlook and VBA | 1 | January 30th 06 10:29 PM |
Automatically trigger a VBA macro to run when connection to exchange server has been made. | [email protected] | Outlook and VBA | 0 | January 25th 06 08:52 PM |