+ Reply to Thread
Results 1 to 2 of 2

Mail sheet(s) to one or more people using VBA in Microsoft Excel

  1. #1
    Registered User
    Join Date
    09-06-2007
    Posts
    1

    Mail sheet(s) to one or more people using VBA in Microsoft Excel

    Hi there,

    I'm using the code below to mail out excel sheets. I'd like to add some notes in the body of the emails- can anyone tell me what I need to do to the code for this?

    Also, is there a way to have multiple recipient addresses in cell C1, rather than a list in separate cells in the column? Separating them using ; doesn't seem to work.

    Thanks a lot
    Paul


    Sub Mail_sheets()
    Dim MyArr As Variant
    Dim last As Long
    Dim shname As Long
    Dim a As Integer
    Dim Arr() As String
    Dim N As Integer
    Dim strdate As String
    For a = 1 To 253 Step 3
    If ThisWorkbook.Sheets("mail").Cells(1, a).Value = "" Then Exit Sub
    Application.ScreenUpdating = False
    last = ThisWorkbook.Sheets("mail").Cells(Rows.Count, a).End(xlUp).Row
    N = 0
    For shname = 1 To last
    N = N + 1
    ReDim Preserve Arr(1 To N)
    Arr(N) = ThisWorkbook.Sheets("mail").Cells(shname, a).Value
    Next shname
    ThisWorkbook.Worksheets(Arr).Copy
    strdate = Format(Date, "dd-mm-yy") & " " & Format(Time, "h-mm-ss")
    ActiveWorkbook.SaveAs "Part of " & ThisWorkbook.Name _
    & " " & strdate & ".xls"
    With ThisWorkbook.Sheets("mail")
    MyArr = .Range(.Cells(1, a + 1), .Cells(Rows.Count, a + 1).End(xlUp))
    End With
    ActiveWorkbook.SendMail MyArr, ThisWorkbook.Sheets("mail").Cells(1, a + 2).Value
    ActiveWorkbook.ChangeFileAccess xlReadOnly
    Kill ActiveWorkbook.FullName
    ActiveWorkbook.Close False
    Application.ScreenUpdating = True
    Next a
    End Sub

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967
    You may need to try making a reference to the Outlook object library and programatically manipulating the MailItem object. There's plenty of examples in Excel help.
    Martin

+ Reply to Thread

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