Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Send mails to users in the excel with the data below.

Avatar of Dave
Dave
Flag of Australia image

how about this.

It sends an email to the person in bold, listing the names of the groups directly below the bold cell

Cheers

Dave
Sub ManagerMail()
    Dim rng1 As Range, rng2 As Range, cel As Range
    Dim doit
    Set rng1 = Sheets(1).Range([a2], Cells(ActiveSheet.Rows.Count, "A").End(xlUp)).SpecialCells(xlConstants)
    For Each cel In rng1
        If cel.Font.Bold Then
            If cel.Offset(2, 0) = vbNullString Then
                Set rng2 = cel.Offset(1, 0)
            Else
                Set rng2 = Range(cel.Offset(1, 0), cel.Offset(1, 0).End(xlDown))
                doit = Mailem(cel.Value, rng2)
            End If
        End If
    Next
End Sub
 
 
Function Mailem(Recip As String, ByVal rng2 As Range)
    Dim outApp, outMail
    Dim cel As Range, tempStr As String
    
    Set outApp = CreateObject("Outlook.Application")
    outApp.Session.Logon
    Set outMail = outApp.CreateItem(0)
    
    For Each cel In rng2
    tempStr = tempStr & cel.Value & vbNewLine
    Next
    
    With outMail
        .To = Recip
        .Subject = "Groups"
        .Recipients.ResolveAll
        .Body = tempStr
        .Display
    End With
    Set outMail = Nothing
    Set outApp = Nothing
End Function

Open in new window

Avatar of bsharath

ASKER

Perfect but i want all that you gave me in the other post.

The grid lined
Body
The footer
Perfect but i want all that you gave me in the other post.

The grid lined
Body
The footer
like so?

Cheers

Dave
Option Explicit
 
Sub ManagerMail()
    Dim rng1 As Range, rng2 As Range, cel As Range
    Dim doit
    Set rng1 = Sheets(1).Range([a1], Cells(ActiveSheet.Rows.Count, "A").End(xlUp)).SpecialCells(xlConstants)
    For Each cel In rng1
        If cel.Font.Bold Then
            If cel.Offset(2, 0) = vbNullString Then
                Set rng2 = cel.Offset(1, 0)
            Else
                Set rng2 = Range(cel.Offset(1, 0), cel.Offset(1, 0).End(xlDown))
                doit = Mailem(cel.Value, rng2)
            End If
        End If
    Next
End Sub
 
 
 
Function Mailem(Recip As String, BodyText As Range)
    Dim outApp, outMail
    Dim tempStrStart As String, tempStrMid As String, tempStrFinish As String, tempStr As String
    Dim cel As Range
    Set outApp = CreateObject("Outlook.Application")
 
    tempStrStart = "<table border=1>"
    tempStrFinish = "</table>"
   
 
    For Each cel In BodyText
        tempStrMid = tempStrMid & "<tr><td>" & cel.Value & "</td>"
    Next
 
    tempStr = tempStrStart & tempStrMid & tempStrFinish
    outApp.Session.Logon
    Set outMail = outApp.CreateItem(0)
    With outMail
        .To = Recip
        .Subject = "Groups"
        .htmlBody = "Hi " & Recip & ",<br>Below is the data.<br>" & tempStr & "<br><br>Regards<br>Sharath"
        .Recipients.ResolveAll
        .Display
    End With
    Set outMail = Nothing
    Set outApp = Nothing
End Function

Open in new window

Works perfect Dave but need a header as

"Groups"
Below is all the data in borders.
"Below is the data."
i dont get a line empty

I get the body as this

Hi sharathr,
Below is the data. (NEED A SPACE BETWEEN THESE LINES)
Products-SGW
Pi Document Templates-SGW
Bacog-SGW


Regards
Sharath
Dave similar type of Q here which i need to send managers the user names who have internet...

https://www.experts-exchange.com/questions/23845484/Filter-colum-'F-and-send-the-user-a-mail-with-the-details.html
ASKER CERTIFIED SOLUTION
Avatar of Dave
Dave
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect Dave thank U...

the same output in the above link too please...