[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 260
  • Last Modified:

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

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 http://www.outlookcode.com/d/code/formontoolbar.htm

  • 3
  • 3
1 Solution
David LeeCommented:
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.

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

ghboomAuthor Commented:

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

David LeeCommented:

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
ghboomAuthor Commented:
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 !!!
ghboomAuthor Commented:
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 ...


David LeeCommented:
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.  

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now