ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Email with excel (https://www.excelbanter.com/excel-discussion-misc-queries/184244-email-excel.html)

jlclyde

Email with excel
 
Here is the code that i have so far. The range A1:A2 is where emails
are stored. The range will become larger when this works correctly.
I am trying to email multiple recipients based on information that I
have in cells on a worksheet. Any guidance woudl be greatly
appreciated.

Sub SendActiveWorkbook()
Dim eMail As String
eMail = ConcRange(Range("A1:A2"), "; ", False, False)
ActiveWorkbook.SendMail _
Recipients:=eMail, _
Subject:="Try Me " & Format(Date, "dd/mmm/yy")
End Sub


Here is the code for the ConcRange function.

Function ConcRange(Substrings As Range, Optional Delim As String =
";", _
Optional AsDisplayed As Boolean = False, Optional SkipBlanks As
Boolean = False)
Dim CLL As Range
For Each CLL In Substrings.Cells
If Not (SkipBlanks And Trim(CLL) = "") Then
ConcRange = ConcRange & Delim & IIf(AsDisplayed,
Trim(CLL.Text), _
Trim(CLL.Value))
End If
Next CLL
ConcRange = Mid$(ConcRange, Len(Delim) + 1)
End Function

Thank You,
Jay

Ron de Bruin

Email with excel
 
See
http://www.rondebruin.nl/mail/tips1.htm

For example

Dim MyArr As Variant
MyArr = Sheets("mysheet").Range("C1:C10")
..SendMail MyArr, "This is the Subject line"




--

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


"jlclyde" wrote in message ...
Here is the code that i have so far. The range A1:A2 is where emails
are stored. The range will become larger when this works correctly.
I am trying to email multiple recipients based on information that I
have in cells on a worksheet. Any guidance woudl be greatly
appreciated.

Sub SendActiveWorkbook()
Dim eMail As String
eMail = ConcRange(Range("A1:A2"), "; ", False, False)
ActiveWorkbook.SendMail _
Recipients:=eMail, _
Subject:="Try Me " & Format(Date, "dd/mmm/yy")
End Sub


Here is the code for the ConcRange function.

Function ConcRange(Substrings As Range, Optional Delim As String =
";", _
Optional AsDisplayed As Boolean = False, Optional SkipBlanks As
Boolean = False)
Dim CLL As Range
For Each CLL In Substrings.Cells
If Not (SkipBlanks And Trim(CLL) = "") Then
ConcRange = ConcRange & Delim & IIf(AsDisplayed,
Trim(CLL.Text), _
Trim(CLL.Value))
End If
Next CLL
ConcRange = Mid$(ConcRange, Len(Delim) + 1)
End Function

Thank You,
Jay



All times are GMT +1. The time now is 05:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com