PC Review


Reply
Thread Tools Rate Thread

Attach Files Listed in Columns with Email

 
 
K
Guest
Posts: n/a
 
      21st Feb 2009
Hi all, I have data in Sheet("Emails") as below

D E ----columns
Email to Each Email to all----headings
C:\My Doc\David Terry.xls C:\ImpFile\Report.pdf
C:\My Doc\Suzan Jones.xlsx C:\ImpFile\Analysis.xlsm
C:\My Doc\Jim Carry.doc
C:\My Doc\Brian Ali.xlsm
C:\My Doc\Simon Johnes.gif

I got file paths in column D and E and I need macro on a button which
should create and display emails according to the numbers of file
paths in column D and attach each file (listed in column D) with each
email and then it should attach all the files listed in column E with
all emails. Please note again that macro should attach each file with
each email (listed in column D) and all files with each email (listed
in column E). For example according to above data macro should create
and display five emails as there are five file paths in column D and
attach each file listed in column D with each email and then there are
two file paths in column E so macro should attach both files with all
emails. I also want that macro should extarct the person's name from
the files which are listed in column D and put in "TO" section of
email, so one of the emails should look like, it should have "David
Terry.xls" file attach and it should also have both files attach which
are "Report.pdf" & "Analysis.xlsm" and in "TO" section of email macro
should extract name from file of column D (which will be the
characters before dot) so in this case "David Terry" and put this in
"TO" section of email. I hope i was able to explain my question.
Please can any friend can help.
 
Reply With Quote
 
 
 
 
Ron de Bruin
Guest
Posts: n/a
 
      21st Feb 2009
Hi K

You can loop through the list and add the files
Here is a example that give you ideas
http://www.rondebruin.nl/mail/folder2/files.htm


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"K" <(E-Mail Removed)> wrote in message news:8f141429-4dd3-4763-a1fb-(E-Mail Removed)...
> Hi all, I have data in Sheet("Emails") as below
>
> D E ----columns
> Email to Each Email to all----headings
> C:\My Doc\David Terry.xls C:\ImpFile\Report.pdf
> C:\My Doc\Suzan Jones.xlsx C:\ImpFile\Analysis.xlsm
> C:\My Doc\Jim Carry.doc
> C:\My Doc\Brian Ali.xlsm
> C:\My Doc\Simon Johnes.gif
>
> I got file paths in column D and E and I need macro on a button which
> should create and display emails according to the numbers of file
> paths in column D and attach each file (listed in column D) with each
> email and then it should attach all the files listed in column E with
> all emails. Please note again that macro should attach each file with
> each email (listed in column D) and all files with each email (listed
> in column E). For example according to above data macro should create
> and display five emails as there are five file paths in column D and
> attach each file listed in column D with each email and then there are
> two file paths in column E so macro should attach both files with all
> emails. I also want that macro should extarct the person's name from
> the files which are listed in column D and put in "TO" section of
> email, so one of the emails should look like, it should have "David
> Terry.xls" file attach and it should also have both files attach which
> are "Report.pdf" & "Analysis.xlsm" and in "TO" section of email macro
> should extract name from file of column D (which will be the
> characters before dot) so in this case "David Terry" and put this in
> "TO" section of email. I hope i was able to explain my question.
> Please can any friend can help.

 
Reply With Quote
 
K
Guest
Posts: n/a
 
      21st Feb 2009
Hi Ron, Thanks for replying. Before putting my question to this
group i did go to your website and looked at this example and tried to
change your file attached code to what i need but wasn't very
successful. I was stuck on extracting the names from file name for
"TO" section of email and also wasn't good to put loop code. I am
glad that you replied for my this question. It will be very nice of
you if you can write me a macro and also explain major parts of your
macro for my knowledge and understanding. I am new learner and it
will be great to learn from people like yourself. Please help
 
Reply With Quote
 
Ron de Bruin
Guest
Posts: n/a
 
      21st Feb 2009
Hi K

I will create a example for you this today or tomorrow

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"K" <(E-Mail Removed)> wrote in message news:54857e66-a8e5-47be-9b40-(E-Mail Removed)...
> Hi Ron, Thanks for replying. Before putting my question to this
> group i did go to your website and looked at this example and tried to
> change your file attached code to what i need but wasn't very
> successful. I was stuck on extracting the names from file name for
> "TO" section of email and also wasn't good to put loop code. I am
> glad that you replied for my this question. It will be very nice of
> you if you can write me a macro and also explain major parts of your
> macro for my knowledge and understanding. I am new learner and it
> will be great to learn from people like yourself. Please help

 
Reply With Quote
 
K
Guest
Posts: n/a
 
      21st Feb 2009
Thanks lot Ron i'll wait for you reply

 
Reply With Quote
 
Ron de Bruin
Guest
Posts: n/a
 
      21st Feb 2009
Try this (change thye sheet name)

Sub Send_Files()
'Working in 2000-2007
Dim OutApp As Object
Dim OutMail As Object
Dim sh As Worksheet
Dim cell As Range, FileCell As Range, rng As Range
Dim Num1 As Long
Dim Num2 As Long

With Application
.EnableEvents = False
.ScreenUpdating = False
End With

Set sh = Sheets("Sheet1")

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon

For Each cell In sh.Columns("D").Cells.SpecialCells(xlCellTypeConstants)

If Dir(cell.Value) <> "" Then

Num1 = InStrRev(cell.Value, "\", , 1)
Num2 = InStrRev(cell.Value, ".", , 1)

Set OutMail = OutApp.CreateItem(0)

With OutMail
.To = Mid(cell.Value, Num1 + 1, Num2 - Num1 - 1)
.Subject = "Testfile"
.Body = "Hi " & cell.Offset(0, -1).Value

If Dir(cell.Value) <> "" Then
.Attachments.Add cell.Value
End If

If Application.WorksheetFunction.CountA(sh.Columns("E")) > 0 Then
For Each FileCell In sh.Columns("E").SpecialCells(xlCellTypeConstants)
If Trim(FileCell) <> "" Then
If Dir(FileCell.Value) <> "" Then
.Attachments.Add FileCell.Value
End If
End If
Next FileCell
End If

.Display 'Or use Send
End With

Set OutMail = Nothing
End If
Next cell

Set OutApp = Nothing

With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"K" <(E-Mail Removed)> wrote in message news:ebdacd65-24c8-4132-8ace-(E-Mail Removed)...
> Thanks lot Ron i'll wait for you reply
>

 
Reply With Quote
 
K
Guest
Posts: n/a
 
      22nd Feb 2009
Thanks for your help and time Ron. Your code works superbly

 
Reply With Quote
 
Ron de Bruin
Guest
Posts: n/a
 
      22nd Feb 2009
You are welcome

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"K" <(E-Mail Removed)> wrote in message news:1675bd80-1604-472f-ad22-(E-Mail Removed)...
> Thanks for your help and time Ron. Your code works superbly
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't attach files to email TonyK Microsoft Outlook Discussion 0 8th Jul 2008 12:34 AM
Cannot Attach files to Email =?Utf-8?B?YmI3Nw==?= Windows XP General 2 15th Nov 2006 01:05 PM
Where files attach in an email? =?Utf-8?B?Sm9lIE1hZ2llcmE=?= Microsoft Outlook Discussion 1 10th Jan 2006 10:27 PM
attach multiple files to an email SUZYQ Microsoft Access 2 23rd Feb 2005 07:34 PM
Cannot attach zip files to email Andy Microsoft Outlook 0 15th Jul 2004 08:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:48 PM.