Outlook button copy "from" addresses to clipboard...

Posted on 2006-03-25
Last Modified: 2008-03-06
I need a macro or vb script that would allow me to select a bunch of emails in outlook and
right click and have all the "from" addresses copied to the clipboard seperated by a LF
after selecting the emails, a button on the tool bar that would add addresses to clip seperated by a LF.

It would also be nice to have the clipboard saved as date-address.txt some where,
but thats allot for the points chosen.

If someone can do both, I will add value to the points awarded ;)

I will add the button by the directions at

Question by:ghboom
    LVL 76

    Expert Comment

    by:David Lee
    Greetings, ghboom.

    I can produce the macro.  There's a hitch though that you need to be aware of.  Accessing an address field, any address field, in Outlook is going to trigger its built-in security which will pop up a dialog-box warning that a program is accessing your mailbox and asking for permission to allow it to continue.  If that's not a problem, then I'll get the code posted.

    LVL 18

    Expert Comment

    To handle the security warning you can use a little utility called ClickYes.

    Author Comment


    By all means its a small price to pay for the convienance !!!

    LVL 76

    Accepted Solution


    Here's the code for doing this.  Follow these instructions to use it.

    1.  Start Outlook
    2.  Click Tools->Macro->Visual Basic Editor
    3.  If not already expanded, expand Modules and click on Module1
    4.  Copy the code below and paste it into the right-hand pane of the VB Editor
    5.  Edit the code as needed.  I put a comment immediately before where something needs to change
    6.  Click Tools->References.
    7.  If not already checked, place a checkmark next to "Microsoft Forms 2.0 Object Library".
    8.  Click the diskette icon on the toolbar to save the changes
    9.  Close the VB Editor
    10.  Click Tools->Macro->Security
    11.  Change the Security Level setting to Medium
    12.  Select the messages you want to save the from address of and run the macro.  It will save them all directly to a text file and to the clipboard at the same time.

    'Macro Begins Here
    Sub SaveFromAddresses()
        Dim olkMessage As Outlook.MailItem, _
            objFSO As Object, _
            objFile As Object, _
            objData As New DataObject, _
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        'Change the path on the following line as needed.
        Set objFile = objFSO.CreateTextFile("C:\eeTesting\" & Year(Date) & StrZero(Month(Date), 2) & StrZero(Day(Date), 2) & ".txt")
        For Each olkMessage In Application.ActiveExplorer.Selection
            objFile.WriteLine olkMessage.SenderEmailAddress
            strAddresses = strAddresses & olkMessage.SenderEmailAddress & vbCrLf
        objData.SetText strAddresses
        Set objData = Nothing
        Set olkMessage = Nothing
        Set objFile = Nothing
        Set objFSO = Nothing
    End Sub

    Function StrZero(varNumber As Variant, intLength As Integer) As String
        Dim intItemLength As Integer, _
            intDifference As Integer
        If IsNumeric(varNumber) Then
            intItemLength = Len(CStr(Int(varNumber)))
            If intItemLength < intLength Then
                intDifference = intLength - intItemLength
                StrZero = String(intDifference, "0") & varNumber
                StrZero = varNumber
            End If
            StrZero = varNumber
        End If
    End Function
    'Macro Ends Here

    Author Comment

    I have not had time to test your solution, but you deserve the points ;)

    I did not want the question PAQed !

    In a day or so I will test and let you know how I made out ;)

    Thanks !!!

    Author Comment

    Well I fgured Im up I might as well...

    I dont have "Microsoft Forms 2.0 Object Library". listed in available refrences ?
    Im using outlook 2002 sp2 on xp sp2 ...


    LVL 76

    Expert Comment

    by:David Lee
    Look in C:\Windows\System32 for a file named FM20.dll  If it's there, then run this command

        regsvr32 c:\windows\fm20.dll

    and see if it appears now.  

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Get an idea of what you should include in an email disclaimer with these Top 5 email disclaimer tips.
    Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now