VB Script - Outlook

Posted on 2011-05-09
Last Modified: 2012-05-11
My OS is windows 7 and the attached code was written by a Super Guru from this Forum.  I am wondering if He or someone could take a look, and see if I could append the emails to the end of the file instead of overwriting it.  I am not sure whether the present code does that or not.  Also if u have the time, could u please add documentation of what each line does - sorry I am just too very basic. thank u.
Sub FwdAddies()
Dim outputFile As Object
Dim objFSO As Object
Dim addy As Variant
Dim mai As Object
Dim strMailAddies As String
Const strFileSpec As String = "c:\deleteme\forwards.txt"

    If TypeName(Application.ActiveWindow) = "Inspector" Then
        Set mai = Application.ActiveInspector.CurrentItem
    ElseIf TypeName(Application.ActiveWindow) = "Explorer" Then
        Set mai = Application.ActiveExplorer.Selection(1)
        Exit Sub
    End If
    If Application.ActiveExplorer.Selection.Count <> 1 Then Exit Sub
    If fnValEmail(mai.Body) And InStr(1, mai.Body, "Forwarded Message", vbTextCompare) Then
        strMailAddies = fnGetEmails(mai.Body)
        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)
        For Each addy In Split(strMailAddies, ",")
            outputFile.Writeline Trim(addy)
        Set outputFile = Nothing
    End If

End Sub

Open in new window

Question by:jegajothy
    LVL 9

    Accepted Solution

    Set outputFile = objFSO.opentextfile(strFileSpec, 8)

    tells that the file has been opened for appending - it is not overwriting the file.


    Author Closing Comment

    Fantastic response.  Thank u.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Introduction It seems that at least a couple of times per month, I answer a question that requires automating Outlook from another Microsoft Office application, usually (although not always) to send one or more email messages.  For example: …
    In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
    The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
    The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

    730 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

    15 Experts available now in Live!

    Get 1:1 Help Now