Email From Contact of Calendar

Status
Not open for further replies.

LMS

Senior Member
Outlook version
Email Account
Exchange Server
Through all I have received, the following is the code that creates an email to a selected or opened or selected contacts individually using email template form, but when I open the contact from a calendar event, it does not recognize the email address of the contact, and it does not work. So what can we fix right away so when I open a contact from a calendar event or an email I received, this macro will create the email to the contact.

Sub Group_Email_Good_Afternoon()
Dim objApp As Application
Dim objNS As NameSpace
Dim objFolder As MAPIFolder
Dim objMsg As mailItem
Dim ObjItem As Object

Set oContact = ObjItem
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")

Set objSelection = objApp.ActiveExplorer.Selection

For Each ObjItem In objSelection


Set objMsg = Application.CreateItemFromTemplate("C:\Users\UserName\AppData\Roaming\Microsoft\Templates\Form1.oft")
With objMsg

.To = ObjItem.Email1Address & ";" & ObjItem.Email2Address

objMsg.Display

End With
'objMsg.Send
Next
Set objMsg = Nothing
Set ObjItem = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objApp = Nothing
End Sub
 
I open it and the code shows yellow collar on the email address line
 
And also, the code does not work when I select and open the contact from the email name of the person that sent the email...so the link is from the email I received...please let me know
 
So you are only opening one contact?
 
Yes. Just opening one contact from an email or calendar event
 
If i get a chance - i need to boot up an old machine so i can test the code (in the other thread) that Michael said should work.
 
You need the links collection if you are going to work with links. This should work - select or open the appointment and run it - it creates one message sent to all contacts in the contacts field. This uses the function here - http://www.slipstick.com/developer/outlook-vba-work-with-open-item-or-select-item/ - which i think you already have.

Code:
Sub GroupEmail()
Dim objMsg As MailItem
Dim objItem As Object
Dim colLinks As Links
  Dim i As Integer
  Dim strAddress As String
 
  Dim oRecip As Recipient
  Dim Recipients As Recipients
 
Set objItem = GetCurrentItem()

Set colLinks = objItem.Links
If colLinks.Count > 0 Then
For i = 1 To colLinks.Count
strAddress = colLinks.Item(i) & ";" & strAddress
Next
End If

Set objMsg = Application.CreateItem(olMailItem)
'Application.CreateItemFromTemplate("C:\Users\UserName\AppData\Roaming\Microsoft\Templates\Form1.oft")

With objMsg

.To = strAddress

objMsg.Display
End With

For Each oRecip In objMsg.Recipients
oRecip.Resolve
Next

Set objMsg = Nothing
Set objItem = Nothing

End Sub
 
Now, if you really want to send to the contact you opened from the field on the appointment, use this one. (It should work for any open contact. )


Code:
Sub MailtoOpenContact()
Dim objApp As Application
Dim objNS As NameSpace
Dim objFolder As MAPIFolder
Dim objMsg As MailItem
Dim ObjItem As Object

Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")

Set ObjItem = objApp.ActiveInspector.currentItem

Set objMsg = Application.CreateItem(olMailItem)
'Set objMsg = Application.CreateItemFromTemplate("C:\Users\UserName\AppData\Roaming\Microsoft\Templates\Form1.oft")

With objMsg
.To = ObjItem.Email1Address '& ";" & ObjItem.Email2Address
objMsg.Display

End With
Set objMsg = Nothing
Set ObjItem = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objApp = Nothing
End Sub
 
Does this work if I open a contact from the person that sends me an email...as I open the contact by clicking on the name of the sender...and my email macros to don't recognize the email address ..that's the error.
 
The first works from the appointment - select the appointment, run the macro and the name(s) in the Contact field are added to an email message. The second one works from an opened contact - and yes, either opened from the contact field in an appointment or using the look up contact command in a message.
 
Set objMsg = Application.CreateItem(olMailItem)
'Set objMsg = Application.CreateItemFromTemplate("C:\Users\UserName\AppData\Roaming\Microsoft\Template.Form.oft


Which of these work re the opening the contact...as I want to user a template form...and that line looks like you stopped it
 
The following works perfect when I open the contact from the folder or from an email or from a calendar, but it does not work if I select two contacts from a folder or select the contact from the folder and not open it, which we did before. So what can I add to this so it works when I open the contact from the folder or from an email or from a calendar, or select one or more contact from a folder and not open it?

Sub MailtoOpenContact()
Dim objApp As Application
Dim objNS As NameSpace
Dim objFolder As MAPIFolder
Dim objMsg As mailItem
Dim objItem As Object
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objItem = objApp.ActiveInspector.currentItem
'Set objMsg = Application.CreateItem(olMailItem)
Set objMsg = Application.CreateItemFromTemplate("C:\Users\UserNameAppData\Roaming\Microsoft\Templates\TemplateName.oft")
With objMsg
.To = objItem.Email1Address & ";" & objItem.Email2Address
objMsg.Display
End With
Set objMsg = Nothing
Set objItem = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objApp = Nothing
End Sub
 
Set objMsg = Application.CreateItem(olMailItem)
'Set objMsg = Application.CreateItemFromTemplate("C:\Users\UserName\AppData\Roaming\Microsoft\Template.Form.oft


Which of these work re the opening the contact...as I want to user a template form...and that line looks like you stopped it
Use your line - i used a blank form in my tests because I didn't have a template in that file path.
 
It worked great. Please see the last question I posted.
 
Selecting two means you need to a loop. If you change this line: Set objItem = objApp.ActiveInspector.currentItem to Set objItem = GetCurrentItem() and use the GetCurrentItem function (which you should have, as you used it in earlier macros) it will work with open or selected items.


To change one or more, you need to use something like this
Code:
For Each obj In objItem
If obj.Class = olContact Then

Set objContact = obj


With objContact
' do whatever

end with

end if
next
 
Thanks very much. As usual, please give me the details of what I add and where to put it. And what do I delete? And does this then do it if I open a contact from a folder, calender or email sender, or select the contact or contacts but not open them? So it is one macro for all ways of using a contact?
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
Witzker Outlook 2019 Macro to seach in all contact Folders for marked Email Adress Outlook VBA and Custom Forms 1
Witzker Outlook 2019 Macro to send an Email Template from User Defined Contact Form Outlook VBA and Custom Forms 0
Witzker Outlook 2019 Edit contact from email does not open the user defined contactform Using Outlook 3
R Roadrunner Email Settings | Contact Roadrunner Customer Support Outlook VBA and Custom Forms 0
N contact list seen in Contact folder but knot in Address book or when 'TO' button is clicked in new email Using Outlook 0
Randy Redekopp How To Merge Contact Info to Email Custom Form Template Using Outlook 2
R Outlook add-in to create new contact from an email. Using Outlook 0
P Skype contact icons have disappeared at the bottom of email and meeting objects Using Outlook 2
Diane Poremsky Add Email Addresses to a Contact Group Using Outlook 0
G Create an Appointment at the Contact's Address From Email Outlook VBA and Custom Forms 0
M creating email from contact file = 3 emails in To field Using Outlook 3
Diane Poremsky Assign an Email Account to an Outlook Contact Using Outlook 0
Z Outlook 2007, clicking email addresses fails to open Contact Using Outlook 0
Diane Poremsky Send email to all addresses for one Contact Using Outlook 0
N linking an already sent/rec'd email to contact record like it did in 2000 Using Outlook 0
D Unable to add email address to contact Using Outlook 3
J Outlook 2010 - email address disappears when setting up new contact Using Outlook 0
L Opening up Contact from an Email - Outlook 2007 Using Outlook 15
P Email Header/People pane/contact card - GAL photo vs. contact photo Using Outlook 7
K Change default "Display As" for contact email addresses Using Outlook 1
D No contact groups in email Using Outlook 4
D Outlook 2010 - email address disappears when setting up new contact Using Outlook 3
K add an email to a business contact without linking/tracking sender BCM (Business Contact Manager) 0
S Contact Photo does not display in email messages. Using Outlook 3
E Double clicking on from email address does no longer open corresponding contact in Outlook 2007 Using Outlook 7
J Contact Email address format Outlook VBA and Custom Forms 3
R My email merge/business contact manager fields are not populating BCM (Business Contact Manager) 1
W email contacts from external contact database. BCM (Business Contact Manager) 1
T How do I get BCM to show up in the email contact field BCM (Business Contact Manager) 1
L VBA to Triage Incoming Email Outlook VBA and Custom Forms 0
R Legacy Outlook on Mac Email Cache Using Outlook 0
P Email address auto-completes work fine on laptop, but no longer on desktop Using Outlook 3
S Create Outlook Task from Template and append Body with Email Body Outlook VBA and Custom Forms 4
H Copying email address(es) in body of email and pasting in To field Outlook VBA and Custom Forms 1
A Search folder and move the email Outlook VBA and Custom Forms 0
P VBA to add email address to Outlook 365 rule Outlook VBA and Custom Forms 0
farrissf Outlook 2016 Optimizing Email Searches in Outlook 2016: Seeking Insights on Quick Search vs Advanced Search Features Using Outlook 0
D Delete selected text in outgoing email body Outlook VBA and Custom Forms 0
F Graphics in email / Mac recipient garbled Using Outlook 0
D Outlook VBA forward the selected email to the original sender’s email ID (including the email used in TO, CC Field) from the email chain Outlook VBA and Custom Forms 2
E Outlook 365 Save Selected Email Message as .msg File - oMail.Delete not working when SEARCH Outlook VBA and Custom Forms 0
S Email Macros to go to a SHARED Outlook mailbox Draft folder...NOT my personal Outlook Draft folder Using Outlook 2
R Outlook 365 VBA AUTO SEND WITH DELAY FOR EACH EMAIL Outlook VBA and Custom Forms 0
G Print email attachments when hit subfolder Outlook VBA and Custom Forms 1
C Spam Email? Using Outlook 2
G Automatically delete email when a condition is met Outlook VBA and Custom Forms 1
E Save Selected Email Message as .msg File - digitally sign email doesn't works Outlook VBA and Custom Forms 1
S Email was migrated from GoDaddy to Microsoft exchange. We lost IMAP ability Exchange Server Administration 1
R Outlook 365 How to integrate a third-party app with Outlook to track email and sms? Using Outlook 2
S Paperclip icon shows without attachment in email under Sent folder Using Outlook 0

Similar threads

Back
Top