Results 1 to 6 of 6

VBA Code to select Range of cells as Email Body In Outlook

Threaded View

  1. #1
    Forum Contributor
    Join Date
    09-05-2012
    Location
    Dubai
    MS-Off Ver
    Office 365
    Posts
    409

    VBA Code to select Range of cells as Email Body In Outlook

    Hi dears i have done a small VBA Code to send the current file as attachment through Outlook.

    file is successfully attached and mail is been sent.

    But my problem is i am unable to fill Body in Mail.

    please find attached i want to select range A1:D18 in sheet (Table) as BODY to my Email.

    code i mentioned below is not working. pls help

    ' .body = ActiveWorkbook.Sheets("Table").Range("A5")
    .body = ActiveWorkbook.Sheets("Table").Range("A1:D18")



    Option Explicit
    Sub Send_Email()
    
    Dim rng As Range
        Dim OutApp As Object
        Dim OutMail As Object
        Dim currentfile, i, finallength, curfile As String
     
     
     currentfile = ActiveWorkbook.FullName
     
     MsgBox currentfile
     
     
        With Application
            .EnableEvents = False
            .ScreenUpdating = False
        End With
     
        Set rng = Nothing
        On Error Resume Next
        Set rng = Selection.SpecialCells(xlCellTypeVisible)
        On Error GoTo 0
     
        If rng Is Nothing Then
            MsgBox "Please select a range or the sheet is protected" & _
                   vbNewLine & "please correct and try again.", vbOKOnly
            Exit Sub
        End If
     
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
     
        On Error Resume Next
        With OutMail
            .To = "naveen.marapaka@aramex.com"
            .CC = "naveen.marapaka@aramex.com"
            .Attachments.Add currentfile
            .Subject = "test"
            .body = ActiveWorkbook.Sheets("Table").Range("A5")
           ' .body = ActiveWorkbook.Sheets("Table").Range("A2:B19")
            .Display
            .Send
        End With
        On Error GoTo 0
     
        With Application
            .EnableEvents = True
            .ScreenUpdating = True
        End With
        
        Set OutMail = Nothing
        Set OutApp = Nothing
    
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1