Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help getting SenderName with a highlighted email

Status
Not open for further replies.

RonQA

Technical User
Jun 24, 2007
61
US
Here is the code I have. It will give me the sender's name if the email is Opened, I need it to give it to me when I highlight the email in the explorer window.

Dim Test As String
Dim myOlApp2 As Outlook.Application
Dim myItem2 As Outlook.MailItem
Set myOlApp2 = CreateObject("Outlook.Application")
Set myItem2 = myOlApp2.ActiveInspector.CurrentItem
Test = myItem2.SenderName
MsgBox (Test)

Any help would be appreciated.

Thanks,
 
Why are you trying to create an extra instance of Outlook? Your code only works because, if Outlook is already running, as you can't have multiple instances, trying to create a second instance just returns the existing one. You just need to use the current Application object.

That said, this is equivalent code to get the selected mail item:

Code:
[blue]    Dim Test As String
    Dim myItem2 As Outlook.MailItem
    Set myItem2 = Application.ActiveExplorer.Selection.Item(1)
    Test = myItem2.SenderName
    MsgBox Test
[/blue]
(assuming, of course, that the active explorer is full of e-mail)

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top