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


VB Script - Outlook

Posted on 2011-05-09
Medium Priority
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

Accepted Solution

sshah254 earned 2000 total points
ID: 35720155
Set outputFile = objFSO.opentextfile(strFileSpec, 8)

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



Author Closing Comment

ID: 35720891
Fantastic response.  Thank u.

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

With its various features, Office 365 can not only help you with your day-to-day business tasks, it can also do wonders for your marketing campaign.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

829 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