save email address Outlook script macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm looking for a macro that will save an email address from the current mail
I'm reading to my address book or to some other file.
 
Try something like this; just amend to suit your purposes.

Sub SaveEmailAddressInOpenedMessageToFile()
On Error Resume Next

Dim objFS As Scripting.FileSystemObject 'Need to set reference to
"Microsoft Scripting Runtime"
Dim objTS As Scripting.TextStream
Dim objInsp As Outlook.Inspector, objMailItem As Outlook.MailItem
Dim strFilePath As String 'Location and name of output file

Set objFS = New Scripting.FileSystemObject
If ActiveInspector Is Nothing Then Exit Sub
Set objInsp = ActiveInspector
If objInsp.CurrentItem.Class <> olMail Then Exit Sub
Set objMailItem = objInsp.CurrentItem

strFilePath = "C:\Temp\emailaddress.txt"

Set objTS = objFS.CreateTextFile(strFilePath, True)
objTS.Write objMailItem.SenderEmailAddress
objTS.Close

Set objTS = Nothing
Set objFS = Nothing
Set objInsp = Nothing
Set objMailItem = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top