travisdh
09-13-2012, 11:33 PM
Hi All,
I am using the below code, to take the selected email and open a subform that contains a lot of text boxes for things like the contact name, email address, address details and so on.
That part works alright, however what i would like to do is look in outlooks contacts for the entry that has the same name, and email address and be able to set the other textboxes in the form to that information. The idea being that i would select an email, and it would extract the users name, the email address, and say a quote or ticket number from that email, and then when i click a button on the userform it would populate all of the users company details, addresses, contact details and so on.
Does anyone have some sample code they would be willing to share that would allow this to be done, once i can get an example of pulling say company name from a contact entry into a variable i can work from there but at the moment I really am quite unsure about how to find a specific entry, have seen so many entries that loop through contacts, but that is not really suitable.
Appreciate any help you can provide.
Thanks!
Sub CreateJob()
Dim myOlExp As Explorer
Dim myOlSel As Selection
Dim myOlMail As MailItem
Dim myXLApp As Excel.Application
Dim myXLWB As Excel.Workbook
Dim extract As String
Dim j As Long
Dim sender As String
Dim email As String
Set myXLApp = New Excel.Application
Set myXLWB = myXLApp.Workbooks.Add
Set myOlExp = ActiveExplorer
Set myOlSel = myOlExp.Selection
Dim standard As String
Dim test As String
For j = 1 To myOlSel.count
Set myOlMail = myOlSel.Item(j)
extract = myOlMail.SenderName
sender = myOlMail.SenderName
email = myOlMail.SenderEmailAddress
Next
UserForm1.Show
UserForm1.txt_clientname.Text = sender
UserForm1.txt_email.Text = email
End Sub
I am using the below code, to take the selected email and open a subform that contains a lot of text boxes for things like the contact name, email address, address details and so on.
That part works alright, however what i would like to do is look in outlooks contacts for the entry that has the same name, and email address and be able to set the other textboxes in the form to that information. The idea being that i would select an email, and it would extract the users name, the email address, and say a quote or ticket number from that email, and then when i click a button on the userform it would populate all of the users company details, addresses, contact details and so on.
Does anyone have some sample code they would be willing to share that would allow this to be done, once i can get an example of pulling say company name from a contact entry into a variable i can work from there but at the moment I really am quite unsure about how to find a specific entry, have seen so many entries that loop through contacts, but that is not really suitable.
Appreciate any help you can provide.
Thanks!
Sub CreateJob()
Dim myOlExp As Explorer
Dim myOlSel As Selection
Dim myOlMail As MailItem
Dim myXLApp As Excel.Application
Dim myXLWB As Excel.Workbook
Dim extract As String
Dim j As Long
Dim sender As String
Dim email As String
Set myXLApp = New Excel.Application
Set myXLWB = myXLApp.Workbooks.Add
Set myOlExp = ActiveExplorer
Set myOlSel = myOlExp.Selection
Dim standard As String
Dim test As String
For j = 1 To myOlSel.count
Set myOlMail = myOlSel.Item(j)
extract = myOlMail.SenderName
sender = myOlMail.SenderName
email = myOlMail.SenderEmailAddress
Next
UserForm1.Show
UserForm1.txt_clientname.Text = sender
UserForm1.txt_email.Text = email
End Sub