Outlook 2007 - vb script

My OS is windows 7.  I tried my hand on editing a macro submitted by a Guru, but it looks like I screwed it up.  It now does not work.  Hope a Guru can please correct the code.  The macro is supposed to copy the receipient's email list to a file on the c drive.  The file is created but the emails are not copied.  The macro is run with the email selected.  thank u.
jegajothyretiredAsked:
Who is Participating?
 
Chris BottomleySoftware Quality Lead EngineerCommented:
The corrected code should be as I posted above, basically you were unaware that in teh original code there was a problem if you simply uncommented everything, that is line 15 above where with thhat disabled the file is opened for append, but when you left that line enabled in your code it replaced the file opened for append with a blank file hence it was just the one line at 'fault'.

Chris
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
What did you change ... upload the script as is and we can take a look.

Chris
0
 
jegajothyretiredAuthor Commented:
in response to Chris, the new script I modified is attached. thank u
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
    MsgBox " I am inside the app "
    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
    MsgBox "end of processing "


End Sub

Open in new window

0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Chris BottomleySoftware Quality Lead EngineerCommented:
At first sight you have enabled the create new and disabled the append block.  Were you trying to append the data to the pre-existing file?, if so ...

Chris
Sub CCorBCC2()

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
    MsgBox " I am inside the app "
    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
    MsgBox "end of processing "


End Sub

Open in new window

0
 
jegajothyretiredAuthor Commented:
in response to Chris, I am trying to create new for the first time, and thence on, to append the block to the already created one.  Hope u can document where in the code I made that boo boo.  thank u.
0
 
jegajothyretiredAuthor Commented:
A word of Art when all pieces fall together. thank u
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.