Outlook 2007 Copy Email Address in To Field

Status
Not open for further replies.

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
There is a story how I need to do this. If there is an email that has not been sent yet, but is open, do we have a macro that copies the email address in the To field, and closes the email not sending it? Here is the code I got before with copies from a field in a contact, but not from an email and its field that is open:

Public Sub CopyAddress()
Dim oContact As contactItem

Set oContact = ActiveExplorer().Selection.Item(1)
Set DataObj = New MSForms.DataObject
DataObj.SetText oContact.UserProperties("LinkedIn Webpage")
DataObj.PutInClipboard
End Sub
 

Forum Admin

Senior Member
The To field is .To - it should work if you properly reference the mailitem instead of contactitem.

Do you need to copy to clipboard or just copy the field to use in another form?
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Got it! Can please show me how to reference the mailitem. As I repeat, i don't have the understanding of these areas so if you can just give me the code to use that would be very helpful to me, which includes closing the email and not sending it.

As to the copy, that email address that is copied, I use the paste code you gave me which puts it in the Email1 field of a contact I select.
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
From another forum over time, I came with the following code that does it.
But here is next major problem, and if we can fix this right now, that would be wonderful!!
When I am on another webpage where I have people that I am connected with through that webpage, for example. LinkedIn, in the contact person area on the webpage there is an email address and when I click on it, it creates an email to that email address, and when I run the code, it closes it, but did not copy the email address in the To field.
What can we change so it copies from that email that is created when I click on an email address in the other webpage?

Public Sub CopyEmailAddress2()
Dim item
Dim inspector
Dim addresses
Dim Recip
Dim myinspector As outlook.inspector
Dim myItem As outlook.mailItem
Set inspector = Application.ActiveInspector
Set item = inspector.currentItem
addresses = ""
For Each Recip In item.Recipients
If Len(addresses) > 0 Then addresses = addresses & "; "
addresses = addresses & Recip.Address
Next
Set DataObj = New MSForms.DataObject
DataObj.SetText addresses
DataObj.PutInClipboard
Set myinspector = Application.ActiveInspector
Set myItem = myinspector.currentItem
myItem.Close olSave
End Sub
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
From another forum over time, I came with the following code that does it.
But here is next major problem, and if we can fix this right now, that would be wonderful!!
When I am on another webpage where I have people that I am connected with through that webpage, for example. LinkedIn, in the contact person area on the webpage there is an email address and when I click on it, it creates an email to that email address, and when I run the code, it closes it, but did not copy the email address in the To field.
What can we change so it copies from that email that is created when I click on an email address in the other webpage?

Public Sub CopyEmailAddress2()
Dim item
Dim inspector
Dim addresses
Dim Recip
Dim myinspector As outlook.inspector
Dim myItem As outlook.mailItem
Set inspector = Application.ActiveInspector
Set item = inspector.currentItem
addresses = ""
For Each Recip In item.Recipients
If Len(addresses) > 0 Then addresses = addresses & "; "
addresses = addresses & Recip.Address
Next
Set DataObj = New MSForms.DataObject
DataObj.SetText addresses
DataObj.PutInClipboard
Set myinspector = Application.ActiveInspector
Set myItem = myinspector.currentItem
myItem.Close olSave
End Sub


And I just changed Recip.Address to Recip.Name and it took care of it.
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Yes.....unless you have other thoughts that are better.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
That looks to be about the best way to do it. At least IMHO.
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
I got it, but don't know what IMHO means
 
Status
Not open for further replies.
Top