"the first SenderEmailAddress in my inbox" doesn't have any precise definition when it comes to programming Outlook. Returning the currently open or currently selected items is no problem, nor is working with all the items in a folder. But if "first" relates to what the user sees, that's not so easy (if it's possible at all) to return that specific item. Maybe you can clarify which item you're interested in.
Note that you can name your variables anything you want. If myItem is already taken, then use myItem2 or myMail or mySandwich. (Sorry, just had lunch.)
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
"BrianL" wrote in message ...
I have been looking at different ways to retrieve email addresses from
senders' mail items, but I have not found one that I can get to work
correctly.
I am trying to open the "new contacts" form and put the sender's address of
the first email in my inbox to the email input. Does that make any sense?
So far I have this code to create a new contact:
Private Sub CommandButton1_Click()
Set myNameSpace = Application.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(10)
Set myItem = Application.CreateItem(2)
myItem.Email1Address =
Unload Me
myItem.Display
End Sub
The only problem is that I don't know how to refrence (is that the right
word?) the first SenderEmailAddress in my inbox. All of the examples I found
concerning this used "myItem" and I'm sure that Outlook wont like me using
two myItem in one sub.
Where would I refrence the address anyway? In the same Private sub or in
ThisOutlookSession?
any tips would be apreciated.