By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,491 Members | 1,168 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,491 IT Pros & Developers. It's quick & easy.

How do I attach multiple files to Mail?

P: 5
I need a piece of code which could attach all the files stored in a folder.
The files in the folder can be *.xls, *.doc or *.pdf. I will be having only the path of the folder and file names in the folder would be dynamic.
Can anyone help me out?
Nov 12 '07 #1
Share this Question
Share on Google+
9 Replies


P: 44
What about calling an open file box for the path with verification on the file name extensions? In case you need you can disable attachments from different path as well. Still in that path you will let the user decide about attaching the file(s).

Or do you want to automate upload, sending etc.? - Using a batch lying in that path for the choice might still be an alternative.
Nov 12 '07 #2

P: 5
What about calling an open file box for the path with verification on the file name extensions? In case you need you can disable attachments from different path as well. Still in that path you will let the user decide about attaching the file(s).

Or do you want to automate upload, sending etc.? - Using a batch lying in that path for the choice might still be an alternative

Thanks for your reply.
I want to automate the upload. The path of the folder is fixed. And I would like to attach all the files in the folder.

Could please help me out?
Nov 12 '07 #3

P: 44
I would just select by " *.* " in the path using the ancient DOS routine. - Hoping you don't use VISTA, in XP it still works.

For that you need to specify the path like " X:\tempor~1\*.* " - I have had some trouble with the long file (directory) names when transfering progs. Using 8 char should be better to keep it from crashing
Nov 12 '07 #4

Expert 5K+
P: 8,435
I think to give any useable advice we need more detail about what you are doing now, in what version of VB. Selecting all the files in a folder in VB is very simple, but the details will vary a bit between versions. And presumably, attaching them to an e-mail will depend on how you are creating the e-mail.
Nov 13 '07 #5

P: 5
I think to give any useable advice we need more detail about what you are doing now, in what version of VB. Selecting all the files in a folder in VB is very simple, but the details will vary a bit between versions. And presumably, attaching them to an e-mail will depend on how you are creating the e-mail.

Here is detail requirement.
Requirement: With cllck of a button. I would like to send a mail and attach the files in a particular folder.

Code:
Private Sub Form_Load()
Dim Olook As Object
Dim Omail As Object
Set Olook = CreateObject("Outlook.Application")
Set Omail = Olook.CreateItem(olMailItem)

MailBody = "Hi ,"
Mail1Body = " Find attached the documents ,"

Omail.To = "new@yahoo.co.in"
Omail.Subject = "Find documents "
Omail.Body = MailBody & vbCrLf & vbCrLf & Mail1Body & EndOfMail

Omail.Display:

Unload Me
End Sub


Problem:
with the above code i am able to compose the mail. I am not sure how to attach files to this mail.
Nov 13 '07 #6

QVeen72
Expert 100+
P: 1,445
Hi,

Take a Look at this M$ Article:
Outlook Attachment

Regards
Veena
Nov 13 '07 #7

P: 5
Hi,

Take a Look at this M$ Article:
Outlook Attachment

Regards
Veena
Thanks for your support.
I looked into the article in the mentioned link.
The code works fine, if you know the filename.

what if the filename keeps changing? (Although path remains the same)
Nov 13 '07 #8

QVeen72
Expert 100+
P: 1,445
Hi,

Place a "File List Box" on the Form, and Change the Path of that and Refresh it. FileListBox will be populated with all the Files in that Folder..
Loop through the List Items (as any Normal ListBox) and it should be done..

some thing like this :

Expand|Select|Wrap|Line Numbers
  1.   Dim MyFileName As String
  2.   Dim i As Integer
  3.   File1.Path = "C:\MyFolder"
  4.   File1.Refresh
  5.   For i = 0 To File1.ListCount-1
  6.       MyFileName = File1.Path & "\" & File1.List(i)
  7.       ' MyFile Name is the File Name in that Folder
  8.       ' Write Your Attachment Code here 
  9.   Next
  10.  

Regards
Veena
Nov 13 '07 #9

Expert 5K+
P: 8,435
Since it looks as though you're using VB6, it's also quite simple to use the Dir() function to retrieve file names. For example, to read all the filenames in the folder Veena used...

Expand|Select|Wrap|Line Numbers
  1. Dim FileName As String
  2. FileName = Dir("C:\MyFolder") ' Find first matching file.
  3. Do While FileName <> ""
  4.   Debug.Print FileName
  5.   FileName = Dir ' No parameters. Just gets next match.
  6. Loop
The advantage of this is that it's quick and simple. It doesn't require a form, a control, or (as the FileSystemObject would) any extra references.
Nov 13 '07 #10

Post your reply

Sign in to post your reply or Sign up for a free account.