Attaching Directory Files to Email (Outlook):   Return to List

Private Sub Command1_Click()
Dim Count As Integer
' First place all of your files in an array
Dim DirectoryFiles()' This must be above Sub Main
ChDir "C:\BarcodeData"' Make barcode data active
directory -- THIS COMMAND might differ

ffile = Dir("*.*")
Do While ffile <> ""
     If ffile <> "" Then
         ReDim Preserve DirectoryFiles(Count)
         DirectoryFiles(Count) = ffile
         Count = Count + 1
     End If
     ffile = Dir()
Loop
' Declare the Outlook object
Dim objoutlook As Object
Dim objoutlookmsg As Object
Set objoutlook = CreateObject("Outlook.application")
Set objoutlookmsg = objoutlook.CreateItem(0)
With objoutlookmsg
    .To = "mymail@mymail.com"
    .Subject = "Test attach files"
    .Body = "Attachment added"
    ' Add as many files as were stored
    For i = 0 To UBound(DirectoryFiles())
        .Attachments.Add DirectoryFiles(i)
    Next
    .Send
End With
Set objoutlook = Nothing
Set objoutlookmsg = Nothing
End Sub



Note to Webmaster