?
Solved

Outlook 2007 - VB code

Posted on 2011-05-07
8
Medium Priority
?
304 Views
Last Modified: 2012-05-11
My OS is windows 7 and I use Outlook 2007.  The attached code will retrieve all the email addresses from a folder, like the Junk folder, and save it as a file.  The code works fine.
I now would like something similar for a different function.
Sometimes u receive an email with hundreds of cc emails and I would like to see who they are preferably as a ASCII file.  The attached code was developed by a super Guru from this forum.  Can a Guru please modify it so that if it is run when a particular email is highlighted, it will only retrieve the email addresses in the cc or bcc addresses fields, and do the same for the rest, i.e. save it as a file.  
Thank u. Code-for-Blocked-emails.txt
0
Comment
Question by:jegajothy
  • 6
  • 2
8 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 35712878
The following is an outlook macro, and it works off the current mail i.e. the active inspector

Modify the :
Const strFileSpec As String = "c:\deleteme\CCorBCC.txt"

to point to the file you want to use

Chris
Sub CCorBCC()
Dim outputFile As Object
Dim objFSO As Object
Dim recip As Recipient
Const strFileSpec As String = "c:\deleteme\CCorBCC.txt"

    If Application.Inspectors.count = 0 Then Exit Sub
'    On Error Resume Next
    Set objFSO = CreateObject("scripting.filesystemobject")
'    Set outputFile = objFSO.opentextfile(strFileSpec, 8)
'    On Error GoTo 0
'    If outputFile Is Nothing Then Set outputFile = objFSO.createtextfile(strFileSpec, True)
    Set outputFile = objFSO.createtextfile(strFileSpec, True)
    For Each recip In Application.ActiveInspector.CurrentItem.Recipients
        If recip.Type <> olCC Or recip.Type = olBCC Then
            outputFile.Writeline recip.address
        End If
    Next
    outputFile.Close
    Set outputFile = Nothing

End Sub

Open in new window

0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 35712887
If you want it driven off the selected item in a folder explorer then:

Chris
Sub CCorBCC()
Dim outputFile As Object
Dim objFSO As Object
Dim recip As Recipient
Const strFileSpec As String = "c:\deleteme\CCorBCC.txt"

    If Application.ActiveExplorer.Selection.count <> 1 Then Exit Sub
'    On Error Resume Next
    Set objFSO = CreateObject("scripting.filesystemobject")
'    Set outputFile = objFSO.opentextfile(strFileSpec, 8)
'    On Error GoTo 0
'    If outputFile Is Nothing Then Set outputFile = objFSO.createtextfile(strFileSpec, True)
    Set outputFile = objFSO.createtextfile(strFileSpec, True)
    For Each recip In Application.ActiveExplorer.Selection(1).Recipients
        If recip.Type <> olCC Or recip.Type = olBCC Then
            outputFile.Writeline recip.address
        End If
    Next
    outputFile.Close
    Set outputFile = Nothing

End Sub

Open in new window

0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 35713061
FWIW, if you want to run the code from the command line as a script working on the selection in outlook ... I imagine not but what the heck

Save teh following as yourchoiceofname.vbs and when executed from the cmd window or by double clicking of the file ... the script will execute on the item selected in outlook

Chris
strFileSpec = "c:\deleteme\CCorBCC.txt"
    set olkApp = createobject("outlook.application")

    If olkApp.ActiveExplorer.Selection.count = 1 Then
    '    On Error Resume Next
        Set objFSO = CreateObject("scripting.filesystemobject")
'        Set outputFile = objFSO.opentextfile(strFileSpec, 8)
'        On Error GoTo 0
'        If outputFile Is Nothing Then Set outputFile = objFSO.createtextfile(strFileSpec, True)
        Set outputFile = objFSO.createtextfile(strFileSpec, True)
        For Each recip In olkApp.ActiveExplorer.Selection(1).Recipients
            If recip.Type <> olCC Or recip.Type = olBCC Then
                outputFile.Writeline recip.address
            End If
        Next
        outputFile.Close
        Set outputFile = Nothing
        set olkapp = nothing
    end if

Open in new window

0
Industry Leaders: 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!

 

Author Comment

by:jegajothy
ID: 35713332
In response to Chris's suggestion,  I first created the directory in the C drive, and then created the macro.  In outlook I highlighted an email that had many cc and Bcc, and then I ran the macro, but it did nothing.  I checked the directory, and nothing was created out there.  Hope u could please debug to see what is wrong. thank j
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 35713358
To use the selected item you need to be using:

http:35712887.html

ALso try modifying the outlook startup see in thisOutlookSession ensure the msgbox is displayed and if it is then the macro ought to work so please walk me through the sequence you are following.

Chris
Private Sub Application_Startup()
    MsgBox "Macros Enabled"
End Sub

Open in new window

0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 2000 total points
ID: 35713365
Just noticed I modified for test purposes ... the following should be used.

Chris
Sub CCorBCC()
Dim outputFile As Object
Dim objFSO As Object
Dim recip As Recipient
Const strFileSpec As String = "c:\deleteme\CCorBCC.txt"

    If Application.ActiveExplorer.Selection.count <> 1 Then Exit Sub
'    On Error Resume Next
    Set objFSO = CreateObject("scripting.filesystemobject")
'    Set outputFile = objFSO.opentextfile(strFileSpec, 8)
'    On Error GoTo 0
'    If outputFile Is Nothing Then Set outputFile = objFSO.createtextfile(strFileSpec, True)
    Set outputFile = objFSO.createtextfile(strFileSpec, True)
    For Each recip In Application.ActiveExplorer.Selection(1).Recipients
        If recip.Type = olCC Or recip.Type = olBCC Then
            outputFile.Writeline recip.address
        End If
    Next
    outputFile.Close
    Set outputFile = Nothing

End Sub

Open in new window

0
 

Author Closing Comment

by:jegajothy
ID: 35713466
I salute as the Master Guru, thank u
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 35713494
Glad to help

Chris
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month16 days, 15 hours left to enroll

864 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