Searching files and email

nazrul10's Avatar, Join Date: Apr 2010
Newbie Member
I have couple of files in a folder like below. I like to email all related zip file to each user. Let say userid : ada_lau has 2 file( and and need to email him( and so on for others.
I need to pickup each userid and need to see whether this userid belongs to any of the zip filename. If this userid is found any of the zip filename then need to email the zip file. Here is my Code:
Const ForReading = 1, ForWriting = 2, ForAppending = 8 
Dim userid, email
Dim Subject
Dim TextBody
Dim MessageAttachment
Dim strFolder
Dim ol, ns, newMail

Const ForReading = 1
MessageSubject = "Test Subject"
MessageBody = "Test body"

Set strFolder = "C:\ScotiaBank\History\output_hist_billing"

Set FSO = CreateObject("Scripting.FileSystemObject")

Set FLD = FSO.GetFolder(strFolder)

Set objUserid = FSO.OpenTextFile("C:\ScotiaBank\History\Email\useridmail.txt", ForReading, True)

Do While objUserid.AtEndOfStream <> True 
      result = Split( Trim(objUserid.ReadLine), "," ) 
      userid= result(0)  
      objMessage.To = email

      'If Userid belongs to any zip files name on strFolder then save it into MessageAttachment variabale and finally email it
      For Each File In FLD.Files
      if UCASE(right(File.Name,13)) = "LETTERPCE.LOG" then
      SET MessageAttachment = "c:\attachment.txt"

'Assume SMTP email server is installed on the machine. 
Set objMessage = CreateObject("CDO.Message") 

objMessage.Subject = "Subject"

objMessage.TextBody = "Historical data, Status = OK"

objMessage.To = email

  objMessage.Attachments.Add(MessageAttachment).Displayname = "Check this out"

Set ol = Nothing
Set objUserid = Nothing 
Set FSO = Nothing

Last edited by shabbir; 22Apr2010 at 23:03.. Reason: Code blocks
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Moved to VB forum