Search code examples
vbaemailoutlookoutlook-2010

Copying New Emails To Address to a Custom Form Outlook 2010


Thanks in advance. The scenario is: When a new email is created containing an address pre-populated in the "To" field then clicking a custom form button, copy that email into the custom form's "To" field and close the original new email. (essentially replacing the original regular email with the form pre-populated with the original "To" address).

The Custom form is working fine but I'm confused on how to talk to or pull the data from that first email to the form when the form opens.


Solution

  • I've modified the Macro that opens my custom form. I've added a button to the quick launch toolbar that appears on every email. The Macro gets the address in the To field of email #1, launches the custom form, places the address into the To field of the custom form, then closes the original (email #1).

    Public Sub ComplexCustomForm()
     Dim olfolder As Outlook.MAPIFolder
     Dim olapp As Outlook.Application
     Dim Items As Outlook.Items
     Dim Item As Object
     Dim m As mailItem
    
     Set m = ActiveInspector.CurrentItem
     f = m.To
     Set olapp = CreateObject("Outlook.Application")
     Set olfolder = olapp.GetNamespace("Mapi").folders("SHARED FOLDER WHERE IPM.Note RESIDES")
    
     Set Items = olfolder.Items
     Set Item = Items.Add("IPM.Note.ComplexCustomForm")
     Item.Display
     Item.To = f
     m.Close olDiscard
    
     Set m = Nothing
     Set olfolder = Nothing
     Set olapp = Nothing
     Set Items = Nothing
     Set Item = Nothing
    End Sub