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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 220
  • Last Modified:

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.
0
jegajothy
Asked:
jegajothy
  • 3
  • 3
1 Solution
 
Chris BottomleyCommented:
What did you change ... upload the script as is and we can take a look.

Chris
0
 
jegajothyAuthor 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
 
Chris BottomleyCommented:
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
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!

 
jegajothyAuthor 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
 
Chris BottomleyCommented:
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
 
jegajothyAuthor Commented:
A word of Art when all pieces fall together. thank u
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

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