We help IT Professionals succeed at work.

Error gathering subject for mail envelope

Murray Brown
Murray Brown asked
on
Hi

I am trying to gather the Subject of the current email in the mail envelope and I am getting an error for
sSubject = Application.ActiveSheet.MailEnvelope.Item.To
sSubject = Application.ActiveSheet.MailEnvelope.To
Comment
Watch Question

SteveCost Accountant
Top Expert 2012

Commented:
Shouldn't it be .Subject not .To:

sSubject = ActiveSheet.MailEnvelope.Item.Subject

Open in new window

Murray BrownASP.net/VBA/VSTO Developer

Author

Commented:
Thanks. When I use that code I get a blank string or "". The image shows that I have something in the subject of my mail
1
SteveCost Accountant
Top Expert 2012

Commented:
Have you tried ConversationTopic ?

sSubject = ActiveSheet.MailEnvelope.Item.ConversationTopic

Open in new window


This may be the 'subject' if subject = ""
Murray BrownASP.net/VBA/VSTO Developer

Author

Commented:
Hi
Thanks. That also returned a blank
SteveCost Accountant
Top Expert 2012

Commented:
OK.. it may be that it uses the filename:

sSubject = ActiveSheet.MailEnvelope.Parent.Name

Open in new window


In my tests it is always the filename.
But the second I put a watch on it , the subject fills in!
Murray BrownASP.net/VBA/VSTO Developer

Author

Commented:
Thanks. I am not sure how to use the filename
SteveCost Accountant
Top Expert 2012

Commented:
Use Parent.name this should be the file name:

sSubject = ActiveSheet.MailEnvelope.Parent.Name

Open in new window

Murray BrownASP.net/VBA/VSTO Developer

Author

Commented:
Hi

Thanks but how do I get the Subject. This only gives me the file name
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015
Commented:
ActiveSheet.MailEnvelope.Item.Subject   is correct.

After changing something in the displayed form, you need to access data like the subject, wait some milliseconds, and then read again. At least that helped when I tried it out just that moment.
Seems to be an issue with the automation interface not properly updating internal data.
Cost Accountant
Top Expert 2012
Commented:
So maybe change the .bcc property as it is likely empty... then you should be able to read the Subject.
Murray BrownASP.net/VBA/VSTO Developer

Author

Commented:
I tried that but couldn't get it to work
Murray BrownASP.net/VBA/VSTO Developer

Author

Commented:
Thanks very much