+ Reply to Thread
Results 1 to 8 of 8

How to create individual sheets from one sheet and email them individually

  1. #1
    Registered User
    Join Date
    06-24-2013
    Location
    Dubai
    MS-Off Ver
    Excel 2010
    Posts
    5

    How to create individual sheets from one sheet and email them individually

    I need a macro for send individual sheet as attachment from a worksheet to email outlook address based on emails (column F) in the attached sample file. Automatically email has to go for all the individual sheets by separate emails.

    Let me know if you need any details.

    Thanks so much in advance.Sample.xlsx

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: How to create individual sheets from one sheet and email them individually

    Hi Shoju

    Welcome to the Forum!

    I'm a bit unclear what you need.

    So I understand...you wish to send the entire Sheet1 an attachment to each individual listed in Column F of Sheet1 and you wish to send the entire Sheet2 as an attachment to each individual listed in Column F of Sheet1?
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    06-24-2013
    Location
    Dubai
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: How to create individual sheets from one sheet and email them individually

    Hi...

    I want to send an attachment(not entire sheet, only each individual details) to each individual listed in Column F of Sheet1.

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: How to create individual sheets from one sheet and email them individually

    Hi Shoju

    I'd be glad to help but I honestly don't understand what it is you want. Try mocking up an example email or two based on the data in your sample file.

  5. #5
    Registered User
    Join Date
    06-24-2013
    Location
    Dubai
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: How to create individual sheets from one sheet and email them individually

    Hi John,

    Weekly basis, I will download this data from SAP (Attached: Sample.xlsx)

    I need a macro for to separate the data according to Personnel no. (Column A) in separate each excel and automatically needs to send an email to each individual personnel no. to respectively email (Column F) with attachment.

    Attached Sample files:
    112537.xlsx
    113214.xlsx
    203047.xlsx

    Sample email i have sent to your email id as attachment..

    Let me know if you want any information

    Thanks in advance....

    Shoju
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: How to create individual sheets from one sheet and email them individually

    Probably you wanna do this.

    See for the code the link to the site of rondebruin.

    http://www.rondebruin.nl/win/s1/outlook/amail3.htm

    Please reply if this is what you're up to.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  7. #7
    Registered User
    Join Date
    06-24-2013
    Location
    Dubai
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: How to create individual sheets from one sheet and email them individually

    Thanks to all..

    I wrote vba code for the above.. Now its working perfectly for the attachment sample data...

    VBA Code:

    Sub SeparateToSheets()
    Dim ws As Worksheet
    Set ws = Sheets("Sheet1")
    Dim LastRow As Long

    LastRow = Range("A" & ws.Rows.Count).End(xlUp).Row

    ' stop processing if we don't have any data
    If LastRow < 2 Then Exit Sub

    Application.ScreenUpdating = False
    SortMasterList LastRow, ws
    CopyDataToSheets LastRow, ws
    ws.Select
    ActiveWindow.SelectedSheets.Delete
    Application.ScreenUpdating = True

    ' Mail send to User with attachment

    Call MailtoSend
    End Sub

    Sub SortMasterList(LastRow As Long, ws As Worksheet)
    ws.Range("A2:M" & LastRow).Sort Key1:=ws.Range("A1"), Key2:=ws.Range("B1")
    End Sub

    Sub CopyDataToSheets(LastRow As Long, src As Worksheet)
    Dim rng As Range
    Dim cell As Range
    Dim Series As String
    Dim SeriesStart As Long
    Dim SeriesLast As Long

    Set rng = Range("A2:A" & LastRow)
    SeriesStart = 2
    Series = Range("A" & SeriesStart).Value
    For Each cell In rng
    If cell.Value <> Series Then
    SeriesLast = cell.Row - 1
    CopySeriesToNewSheet src, SeriesStart, SeriesLast, Series
    Series = cell.Value
    SeriesStart = cell.Row
    End If
    Next
    ' copy the last series
    SeriesLast = LastRow
    CopySeriesToNewSheet src, SeriesStart, SeriesLast, Series

    End Sub

    Sub CopySeriesToNewSheet(src As Worksheet, Start As Long, Last As Long, name As String)
    Dim tgt As Worksheet

    If (SheetExists(name)) Then
    MsgBox "Sheet " & name & " already exists. " _
    & "Please delete or move existing sheets before" _
    & " copying data from the Master Sheet.", vbCritical, _
    "Duplicate"
    End
    End If

    Worksheets.Add(After:=Worksheets(Worksheets.Count)).name = name
    Set tgt = Sheets(name)

    ' copy header row from src to tgt
    tgt.Range("A1:M1").Value = src.Range("A1:M1").Value

    ' copy data from src to tgt
    tgt.Range("A2:M" & Last - Start + 2).Value = _
    src.Range("A" & Start & ":M" & Last).Value

    End Sub

    Function SheetExists(name As String) As Boolean
    Dim ws As Worksheet

    SheetExists = True
    On Error Resume Next
    Set ws = Sheets(name)
    If ws Is Nothing Then
    SheetExists = False
    End If
    End Function

    Sub MailtoSend()
    Dim onePublishObject As PublishObject
    Dim oneSheet As Worksheet
    Dim scriptingObject As Object
    Dim outlookApplication As Object
    Dim outlookMail As Object
    Dim htmlBody As String
    Dim htmlFile As String
    Dim textStream, fil As String
    Dim dummy As Workbook


    Today = Format(Now(), "dd-mm-yyyy")

    Set dummy = ActiveWorkbook
    Set scriptingObject = CreateObject("Scripting.FileSystemObject")
    Set outlookApplication = CreateObject("Outlook.Application")
    For Each oneSheet In ActiveWorkbook.Worksheets

    Dim StrBody As String
    Dim strTo As String

    strTo = oneSheet.name
    StrBody = " THIS IS A TEST" & " " & UCase(oneSheet.name) & " " & "XYZ," & vbNewLine & _
    vbNewLine & _
    "Please FIND ATTACHED <B>'XYZ REPORT'<B>"


    Application.DisplayAlerts = False
    Sheets(oneSheet.name).Copy
    ActiveWorkbook.SaveAs dummy.Path & "\" & oneSheet.name & ".xlsx"
    ActiveWorkbook.Close
    Application.DisplayAlerts = True
    Set outlookMail = outlookApplication.CreateItem(0)
    With outlookMail
    .To = strTo
    .htmlBody = StrBody & htmlBody
    .attachments.Add dummy.Path & "\" & oneSheet.name & ".xlsx"
    .Display
    .Subject = "XYZ Report" & " " & UCase(oneSheet.name) & " " & "(" & Today & ")"
    '.Send
    End With
    Next oneSheet
    End Sub

  8. #8
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: How to create individual sheets from one sheet and email them individually

    @sjohu

    Please add the code between codetags ##

    Did you used the link to the side from Ron de Bruin to get your resultmacro?

    Please reply.

  9. #9
    Registered User
    Join Date
    06-24-2013
    Location
    Dubai
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: How to create individual sheets from one sheet and email them individually

    No.. i never used the site from Ron de Bruin...

    Please Login or Register  to view this content.

+ 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