![]() |
| 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. |
|
|||||||
| Tags: custom, form, generate, item_send, message, noncustom |
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
I noticed a brief reference in a previous posting about using code in a
custom form's Item_Send event handler to generate a new, non-custom-form message. I need to do exactly this. How can I accomplish this? I am relatively new to VBA in Outlook, so treat me as a novice. Thank you! |
| Ads |
|
#2
|
|||
|
|||
|
It would be VBScript code, not VBA, because that's what Outlook custom forms use, and would look something like this, to create a new plain text message. Note that you need to add CopyAtts subroutine from http://www.outlookcode.com/d/code/copyatts.htm to this script.
Function Item_Send() Dim objMsg ' As Outlook.MailItem Dim objRecip ' As Outlook.Recipient Dim objNewRecip ' As Outlook.Recipient Const olMailItem = 0 Const olFormatPlain = 1 On Error Resume Next Item_Send = False Set objMsg = Application.CreateItem(olMailItem) For Each objRecip In Item.Recipients Set objNewRecip = _ objMsg.Recipients.Add(objRecip.address) If objNewRecip.Resolve Then objNewRecip.Type = objRecip.Type End If Next If Item.Attachments.Count 0 Then ' Add CopyAtts function from ' http://www.outlookcode.com/d/code/copyatts.htm ' to this script. Call CopyAtts(Item, objMsg) End If With objMsg .BodyFormat = olFormatPlain .Body = Item.Body .DeferredDeliveryTime = Item.DeferredDeliveryTime .DeleteAfterSubmit = Item.DeleteAfterSubmit .ExpiryTime = Item.ExpiryTime .Importance = Item.Importance .OriginatorDeliveryReportRequested = _ Item.OriginatorDeliveryReportRequested .ReadReceiptRequested = _ Item.ReadReceiptRequested .Subject = Item.Subject If .Recipients.count 0 _ And .Recipients.ResolveAll Then .Send MsgBox "Message sent successfully. " & _ "You can close the original now." Else .Display End If End With Set objMsg = Nothing Set objRecip = Nothing Set objNewRecip = Nothing End Function -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "supportusa" wrote in message ... I noticed a brief reference in a previous posting about using code in a custom form's Item_Send event handler to generate a new, non-custom-form message. I need to do exactly this. How can I accomplish this? I am relatively new to VBA in Outlook, so treat me as a novice. Thank you! |
|
#3
|
|||
|
|||
|
Thank you, Sue. I ran this code in a custom form (without the CopyAtts
subroutine), and it appeared to run. I got the successful message at the end of the script. However, the message that was received on the other end was blank. Do I need to customize any of the script? I just ran it as it is. "Sue Mosher [MVP-Outlook]" wrote: It would be VBScript code, not VBA, because that's what Outlook custom forms use, and would look something like this, to create a new plain text message. Note that you need to add CopyAtts subroutine from http://www.outlookcode.com/d/code/copyatts.htm to this script. Function Item_Send() Dim objMsg ' As Outlook.MailItem Dim objRecip ' As Outlook.Recipient Dim objNewRecip ' As Outlook.Recipient Const olMailItem = 0 Const olFormatPlain = 1 On Error Resume Next Item_Send = False Set objMsg = Application.CreateItem(olMailItem) For Each objRecip In Item.Recipients Set objNewRecip = _ objMsg.Recipients.Add(objRecip.address) If objNewRecip.Resolve Then objNewRecip.Type = objRecip.Type End If Next If Item.Attachments.Count 0 Then ' Add CopyAtts function from ' http://www.outlookcode.com/d/code/copyatts.htm ' to this script. Call CopyAtts(Item, objMsg) End If With objMsg .BodyFormat = olFormatPlain .Body = Item.Body .DeferredDeliveryTime = Item.DeferredDeliveryTime .DeleteAfterSubmit = Item.DeleteAfterSubmit .ExpiryTime = Item.ExpiryTime .Importance = Item.Importance .OriginatorDeliveryReportRequested = _ Item.OriginatorDeliveryReportRequested .ReadReceiptRequested = _ Item.ReadReceiptRequested .Subject = Item.Subject If .Recipients.count 0 _ And .Recipients.ResolveAll Then .Send MsgBox "Message sent successfully. " & _ "You can close the original now." Else .Display End If End With Set objMsg = Nothing Set objRecip = Nothing Set objNewRecip = Nothing End Function -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "supportusa" wrote in message ... I noticed a brief reference in a previous posting about using code in a custom form's Item_Send event handler to generate a new, non-custom-form message. I need to do exactly this. How can I accomplish this? I am relatively new to VBA in Outlook, so treat me as a novice. Thank you! |
|
#4
|
|||
|
|||
|
After the code sets the Body property, you might want to throw in a MsgBox objMsg.Body statement to see what Outlook thinks the new message body contains. Also make sure you're up-to-date on Outlook patches, since there have been some blank message issues in some versions.
-- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "supportusa" wrote in message ... Thank you, Sue. I ran this code in a custom form (without the CopyAtts subroutine), and it appeared to run. I got the successful message at the end of the script. However, the message that was received on the other end was blank. Do I need to customize any of the script? I just ran it as it is. "Sue Mosher [MVP-Outlook]" wrote: It would be VBScript code, not VBA, because that's what Outlook custom forms use, and would look something like this, to create a new plain text message. Note that you need to add CopyAtts subroutine from http://www.outlookcode.com/d/code/copyatts.htm to this script. Function Item_Send() Dim objMsg ' As Outlook.MailItem Dim objRecip ' As Outlook.Recipient Dim objNewRecip ' As Outlook.Recipient Const olMailItem = 0 Const olFormatPlain = 1 On Error Resume Next Item_Send = False Set objMsg = Application.CreateItem(olMailItem) For Each objRecip In Item.Recipients Set objNewRecip = _ objMsg.Recipients.Add(objRecip.address) If objNewRecip.Resolve Then objNewRecip.Type = objRecip.Type End If Next If Item.Attachments.Count 0 Then ' Add CopyAtts function from ' http://www.outlookcode.com/d/code/copyatts.htm ' to this script. Call CopyAtts(Item, objMsg) End If With objMsg .BodyFormat = olFormatPlain .Body = Item.Body .DeferredDeliveryTime = Item.DeferredDeliveryTime .DeleteAfterSubmit = Item.DeleteAfterSubmit .ExpiryTime = Item.ExpiryTime .Importance = Item.Importance .OriginatorDeliveryReportRequested = _ Item.OriginatorDeliveryReportRequested .ReadReceiptRequested = _ Item.ReadReceiptRequested .Subject = Item.Subject If .Recipients.count 0 _ And .Recipients.ResolveAll Then .Send MsgBox "Message sent successfully. " & _ "You can close the original now." Else .Display End If End With Set objMsg = Nothing Set objRecip = Nothing Set objNewRecip = Nothing End Function "supportusa" wrote in message ... I noticed a brief reference in a previous posting about using code in a custom form's Item_Send event handler to generate a new, non-custom-form message. I need to do exactly this. How can I accomplish this? I am relatively new to VBA in Outlook, so treat me as a novice. Thank you! |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Custom Form - Receiver replies and form is gone, message body is b | Kozlik | Outlook - Using Forms | 16 | July 14th 06 10:32 PM |
| Emailing a contact vCard with custom form loses all custom info | Kim | Outlook - Using Contacts | 7 | April 27th 06 01:21 AM |
| How to add sender name to cc for Custom Message form in Outlook | David Tallahassee | Outlook - Using Forms | 2 | March 29th 06 09:27 PM |
| opening new custom Message form | Melbin | Outlook - Using Forms | 2 | January 24th 06 01:16 PM |
| Cannot programmatically open custom message in custom form | ms | Outlook - Using Forms | 1 | January 20th 06 04:01 PM |