Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Vb Script email attachment with multiple files

Vb Script email attachment with multiple files

Vb Script email attachment with multiple files

I need your help. I have to attach 2 files to an email but I can only do so with one with the current script.
Also the file names are specific hence the sFileNameStart and sFileNameEnd
2 file names are

Const startDir = "C:\scripts\blah"
Set oFSO = CreateObject("Scripting.FileSystemObject")
DateToday = Year(Date) & Right("0" & Month(Date), 2) & Right("0" & Day(Date), 2)
sFileNameStart = "KFC" & DateToday
sFileNameEnd = ".xls"
Set objEmail = CreateObject("CDO.Message")
Set oFolder = oFSO.GetFolder(startDir)
sFullFileName = ""
Recurse oFolder
If sFullFileName <> "" Then
WScript.Echo "No File Exists."
End If

Sub Recurse(oFldr)
For Each oSubFolder In oFldr.SubFolders
Recurse oSubFolder
For Each oFile In oFldr.Files
If Left(LCase(oFile.Name), Len(sFileNameStart)) = LCase(sFileNameStart) And _
Right(LCase(oFile.Name), Len(sFileNameEnd)) = LCase(sFileNameEnd) Then
sFullFileName = oFile.Name
Exit Sub
End If
End Sub

Sub sendEmail()
objEmail.From = "blah@blah.org"
objEmail.To = "blah@blah.org"
objEmail.Subject = "Daily blah Files"
objEmail.Textbody = "Please see attached for today's files."
objEmail.AddAttachment startDir & "\" & sFullFileName
With objEmail.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sen...") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smt...") = "blah.blah1.org" ' Mail Server to use for SMTP"
.Item("http://schemas.microsoft.com/cdo/configuration/smt...") = 25
End With
End Sub

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close