+ Reply to Thread
Results 1 to 5 of 5

Vba to attach worksheet to email addresses in the workbook

  1. #1
    Registered User
    Join Date
    10-02-2017
    Location
    Swansea
    MS-Off Ver
    2007
    Posts
    14

    Vba to attach worksheet to email addresses in the workbook

    Hi sorry if this is already on her but I've been looking for 3 days now and cant find the answer.

    I have the following VBA that will send a email to the address in the workbook But I need it to only send one spastic sheet names “Time”.
    Ok as ap new book single sheet or a PDF what ever works


    [Sub EmailAttachmentRecipients()


    ActiveSheet.Unprotect Password:="123"




    Dim objOutlook As Object
    Dim objNameSpace As Object
    Dim objInbox As Object
    Dim objMailItem As Object
    Set objOutlook = CreateObject("Outlook.Application")
    Set objNameSpace = objOutlook.GetNamespace("MAPI")
    Set objInbox = objNameSpace.Folders(1)
    Set objMailItem = objOutlook.CreateItem(0)


    Dim StrTo As String
    Dim i As Integer
    StrTo = ""
    i = 1


    With Worksheets("Email")
    Do
    StrTo = StrTo & .Cells(i, 1).Value & "; "
    i = i + 1
    Loop Until IsEmpty(.Cells(i, 1))
    End With


    StrTo = Mid(StrTo, 1, Len(StrTo) - 2)


    With objMailItem
    .To = StrTo
    .CC = ""
    .Subject = "Time sheet for " & Format(Sheets("Email").Range("n2")) & Format(Sheets("Email").Range("L2"))
    .Body = _
    "Hi," & Chr(10) & Chr(10) & _
    "Please see attached Time sheet for the above individual" & Chr(10) & _
    ""
    .Attachments.Add ActiveWorkbook.FullName
    .Display
    End With




    Set objOutlook = Nothing
    Set objNameSpace = Nothing
    Set objInbox = Nothing
    Set objMailItem = Nothing


    ActiveSheet.Protect Password:="123"


    End Sub]

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Vba to attach worksheet to email addresses in the workbook

    Use this code
    Mail one sheet

    Change the line...
    ActiveSheet.Copy
    To...
    Sheets("Time").Copy
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    10-02-2017
    Location
    Swansea
    MS-Off Ver
    2007
    Posts
    14

    Re: Vba to attach worksheet to email addresses in the workbook

    Hi AlphFrog,
    Thanks for the reply but sorry I don’t know what you mean I don’t have a line activesheet copy, to be able to change it, I should do but not sure how to get it into the code.

    At the moment it attaches the entire work book I just need one sheet.


    Thanks in advance

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Vba to attach worksheet to email addresses in the workbook

    Click on the link, and use THAT code, but change the one line in that code.

  5. #5
    Registered User
    Join Date
    10-02-2017
    Location
    Swansea
    MS-Off Ver
    2007
    Posts
    14

    Re: Vba to attach worksheet to email addresses in the workbook

    Hi that’s great, thanks very much for the help. Sorry I missed the link

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 14
    Last Post: 05-08-2017, 04:17 PM
  2. attach different worksheet and email them tdifferent email address through macro/vba/addin
    By arunverma004 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-03-2014, 08:20 AM
  3. Save workbook, attach it to outlook email, close workbook?
    By Jasonhouse in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-27-2014, 11:52 PM
  4. [SOLVED] Email Macro to attach a non active worksheet to outlook email
    By mickgibbons1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-21-2013, 08:38 PM
  5. Launch email and attach open workbook to email?
    By mlefkowitz in forum Excel General
    Replies: 0
    Last Post: 09-11-2012, 02:01 PM
  6. email excel file or worksheet as an attachment to multiple email addresses
    By jgeagle5 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-16-2009, 03:40 PM
  7. Email workbook AND attach a separate file to the email
    By sgreni in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-15-2009, 06:48 PM

Tags for this Thread

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