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
 
Yes. Just opening one contact from an email or calendar event
 
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
N Why does Outlook keeping adding to the email address I have in my notes portion of a contact? Using Outlook 2
Witzker Outlook 2019 Macro to seach in all contact Folders for marked Email Adress Outlook VBA and Custom Forms 0
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
P SPAM message about Comcast email migration to Yahoo Using Outlook 1
P anything new on the supposed shutdown of comcast.net email? Using Outlook 6
S Is there an add-in to PDF entire folders of email with Microsoft 365? Using Outlook 4
W frustrating trying to change email password Using Outlook 5
R File not found when sending email with attached pdf file Using Outlook 2
U Trouble sending large files to a email group but can to the individuals in that group Using Outlook 8
P Xfinity/Comcast email service stopping sometime in 2025 - warning Using Outlook 5
O Two identical email accounts in Offline Global Address List Using Outlook 2
H Spam email in Gmail not visible in Outlook Using Outlook 3
J Renegade spam URL line displayed in old local Outlook 365 email title Using Outlook 3
L Hide Selected Email Address from Address Book Using Outlook 5
Y QQ on Scheduled Delivery of an Email Using Outlook 0
T Replace Text in Email Subject Outlook VBA and Custom Forms 3
Rupert Dragwater Cannot reestablish gmail (email address) account in Outlook 365 Using Outlook 11
M Outlook 365 adding standard message in body of template email Outlook VBA and Custom Forms 3
E Create Rule to Forward Email if Subject Begins With Using Outlook 2
V iCloud For Windows v15.x - Missing Email Features ? Using Outlook 4
M Thunderbird email client - I wonder Using Outlook 1
D Outlook Desktop App Email Software Using Outlook 0
P Email and calendar entry text now shifts right about 3 tabs worth of space Using Outlook 1

Similar threads

Back
Top