Attach all the files within a folder

Shank
Sub SendEmailUsingGmail()
Dim Text As String, StrPath As String, StrFile As String
Dim Text2 As String
Dim Text3 As String
Dim i As Integer
Dim j As Integer
Dim NewMail As CDO.Message



i = 1
Do While Cells(i, 1).Value <> ""

    Set NewMail = New CDO.Message

    NewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True

    'Make SMTP authentication Enabled=true (1)

    NewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

    'Set the SMTP server and port Details
    'To get these details you can get on Settings Page of your Gmail Account

    NewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"

    NewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465

    NewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

    'Set your credentials of your Gmail Account

    NewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "[email protected]"

    NewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "****"

     'Update the configuration fields
    NewMail.Configuration.Fields.Update

    With NewMail
        StrPath = Cells(i, 2).Value
        .Subject = ""
        ' adds the data in column3 with space as subject
        .From = "[email protected]"

         Text = Cells(i, 1).Value
         StrFile = Dir(StrPath & "*.txt")
         'Text2 = Cells(i, 2).Value

        .To = Text
        .BCC = ""
        .TextBody = "WDAdsas"
        .AddAttachment StrFile
        .Send
    End With
    i = i + 1
Loop

End Sub

My excel contains email id in the first column, the second column has the address of each attachment:(Excel looks like)

[email protected]   E:\Shank E drive\Gon\EBooks\BBB\
shank@gwu.      E:\Shank E drive\Gon\EBooks\AAA\

When I debug step by step the I get the txt file in StrFile but the addattachment is not able to read it.

It gives the error specified protocol is unkown.

Histerical
StrPath= Column2Range
FileType = "*.txt"

strFile = Dir(StrPath & FileType)
If Len(strFile ) = 0 Then
  GoTo ExitProc
End If
  Do While Len(strFile ) > 0
  .AddAttachment StrPath & strFile 
  strFile = Dir
Loop
ExitProc:

This should work for you. Let me know if you need help making sense of it.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

git not pushing all files within folder

From Dev

Transposing all csv files within a folder

From Dev

Finding the number of rows for all files within a folder

From Dev

Finding the number of rows for all files within a folder

From Dev

Move all files within subfolders to parent folder

From Dev

Rename all files within a folder prefixed with foldername

From Dev

redirect all files within the same folder to the index page (same folder)

From Dev

Counting all occurrences of a string within all files in a folder

From Dev

How to remove all empty files within folder and its sub folders?

From Dev

Merge all .gpx files within a folder into one file with GPSbabel

From Dev

R doesn't list all files within folder

From Dev

How to convert all pdf files to text (within a folder) with one command?

From Dev

How to convert all pdf files to text (within a folder) with one command?

From Dev

Sort All Files (any depth) within a Folder by Size

From Dev

How to open all programs/files shortcuts within a folder

From Dev

R doesn't list all files within folder

From Dev

How to rename all files within a folder not starting with a specific prefix string?

From Dev

How to average all files within a folder by image j macro

From Dev

uuencode to attach all files in a directory

From Dev

Searching for files within specific folder

From Dev

Renaming all files in a folder

From Dev

How can I enumerate all files in an S3 folder within a bucket?

From Dev

With vb.net, Is there a way to find all compressed files within a folder and its subfolders?

From Dev

Create a standalone html page which shows the contents of all files within a folder

From Dev

How to open a remote folder to edit all files within using winscp/cyberduck?

From Dev

I have many single files nested within many folders. Is there a way in Mac OSX to extract all the files into one folder?

From Dev

chmod 775 on a folder but not all files under that folder

From Dev

chmod 775 on a folder but not all files under that folder

From Dev

Robocopy all files in a folder except that folder

Related Related

  1. 1

    git not pushing all files within folder

  2. 2

    Transposing all csv files within a folder

  3. 3

    Finding the number of rows for all files within a folder

  4. 4

    Finding the number of rows for all files within a folder

  5. 5

    Move all files within subfolders to parent folder

  6. 6

    Rename all files within a folder prefixed with foldername

  7. 7

    redirect all files within the same folder to the index page (same folder)

  8. 8

    Counting all occurrences of a string within all files in a folder

  9. 9

    How to remove all empty files within folder and its sub folders?

  10. 10

    Merge all .gpx files within a folder into one file with GPSbabel

  11. 11

    R doesn't list all files within folder

  12. 12

    How to convert all pdf files to text (within a folder) with one command?

  13. 13

    How to convert all pdf files to text (within a folder) with one command?

  14. 14

    Sort All Files (any depth) within a Folder by Size

  15. 15

    How to open all programs/files shortcuts within a folder

  16. 16

    R doesn't list all files within folder

  17. 17

    How to rename all files within a folder not starting with a specific prefix string?

  18. 18

    How to average all files within a folder by image j macro

  19. 19

    uuencode to attach all files in a directory

  20. 20

    Searching for files within specific folder

  21. 21

    Renaming all files in a folder

  22. 22

    How can I enumerate all files in an S3 folder within a bucket?

  23. 23

    With vb.net, Is there a way to find all compressed files within a folder and its subfolders?

  24. 24

    Create a standalone html page which shows the contents of all files within a folder

  25. 25

    How to open a remote folder to edit all files within using winscp/cyberduck?

  26. 26

    I have many single files nested within many folders. Is there a way in Mac OSX to extract all the files into one folder?

  27. 27

    chmod 775 on a folder but not all files under that folder

  28. 28

    chmod 775 on a folder but not all files under that folder

  29. 29

    Robocopy all files in a folder except that folder

HotTag

Archive