Question : Outlook Macro to query a txt file and send emails.

Hi,

Outlook Macro to query a txt file and send emails.
I want help with a macro when run checks a txt file that has data as this

Filename1;Email address
Filename2;Email address
Filename3;Email address

The file name has to be checked in a folder where all these txt files are available and then email the txt file content into the body and email address in the TO box
Each email address would be different

A subject like with a little bod data
I want the txt content into a table. So it looks neat.

Regards
Sharath

Answer : Outlook Macro to query a txt file and send emails.

Ok, try this.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
Sub ImportFromFileAndSend()
    Dim objFSO As Object, _
        objFile1 As Object, _
        objFile2 As Object, _
        olkMsg As Object, _
        strBuffer As String, _
        arrParts As Variant, _
        strTable As String
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    'On the next line edit the file name and path.'
    Set objFile1 = objFSO.OpenTextFile("C:\eeTesting\masterfile.txt")
    Do Until objFile1.AtEndOfStream
        strBuffer = objFile1.ReadLine
        arrParts = Split(strBuffer, ";")
        Set olkMsg = Application.CreateItem(olMailItem)
        With olkMsg
            'On the next line edit the file path.'
            Set objFile2 = objFSO.OpenTextFile("C:\eeTesting\" & arrParts(0))
            'On the next line change the subject as desired.'
            .Subject = "Your Subject Goes Here"
            .To = arrParts(1)
            .BodyFormat = olFormatHTML
            Do Until objFile2.AtEndOfStream
                'On the next line edit the HTML as desired.'
                strTable = strTable & "<tr><td style=""background-color:#d0d0d0"">" & objFile2.ReadLine & "</td><td style=""background-color:#f0f0f0"">&nbsp;</td></tr>"
            Loop
            'On the next line edit the message as desired.'
            .HTMLBody = "Hi,<br><br><table style=""width: 100%""><tr><td style=""background-color:#d0d0d0; width:50%""><b>Software Name</b></td><td style=""background-color:#f0f0f0; width:50%""><b>Comments</b></td></tr>" & strTable & "</table><br><br>Regards<br>Somename"
            .Display
        End With
        objFile2.Close
    Loop
    Set olkMsg = Nothing
    Set objFile1 = Nothing
    Set objFile2 = Nothing
    Set objFSO = Nothing
End Sub
Random Solutions  
 
programming4us programming4us