+ Reply to Thread
Results 1 to 3 of 3

VBA Macro Sent Range of Cells and Email from a Pick List

  1. #1
    Forum Contributor
    Join Date
    08-29-2014
    Location
    Chicago, IL
    MS-Off Ver
    2014
    Posts
    164

    VBA Macro Sent Range of Cells and Email from a Pick List

    I have the following VBA code that will allow you to select an excel range and it will email that range. I am limited to the email address added in the code, so I would like to be able to select from a list of email addresses because the range of cells will be going to different people. Perhaps I can have a data validation list on a worksheet and have the email address I want selected and have the code email to that address?




    Sub SendRange()
    'Update 20131209
    Dim xFile As String
    Dim xFormat As Long
    Dim Wb As Workbook
    Dim Wb2 As Workbook
    Dim Ws As Worksheet
    Dim FilePath As String
    Dim FileName As String
    Dim OutlookApp As Object
    Dim OutlookMail As Object
    Dim WorkRng As Range
    xTitleId = "KutoolsforExcel"
    Set WorkRng = Application.Selection
    Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Set Wb = Application.ActiveWorkbook
    Wb.Worksheets.Add
    Set Ws = Application.ActiveSheet
    WorkRng.Copy Ws.Cells(1, 1)
    Ws.Copy
    Set Wb2 = Application.ActiveWorkbook
    Select Case Wb.FileFormat
    Case xlOpenXMLWorkbook:
    xFile = ".xlsx"
    xFormat = xlOpenXMLWorkbook
    Case xlOpenXMLWorkbookMacroEnabled:
    If Wb2.HasVBProject Then
    xFile = ".xlsm"
    xFormat = xlOpenXMLWorkbookMacroEnabled
    Else
    xFile = ".xlsx"
    xFormat = xlOpenXMLWorkbook
    End If
    Case Excel8:
    xFile = ".xls"
    xFormat = Excel8
    Case xlExcel12:
    xFile = ".xlsb"
    xFormat = xlExcel12
    End Select
    FilePath = Environ$("temp") & ""
    FileName = Wb.Name & Format(Now, "dd-mmm-yy h-mm-ss")
    Set OutlookApp = CreateObject("Outlook.Application")
    Set OutlookMail = OutlookApp.CreateItem(0)
    Wb2.SaveAs FilePath & FileName & xFile, FileFormat:=xFormat
    With OutlookMail
    .To = "[email protected]"
    .CC = ""
    .BCC = ""
    .Subject = "Pending Order Work Request"
    .Body = "Please complete the pending order you are currently working and then begin working this list. "
    .Attachments.Add Wb2.FullName
    .Send
    End With
    Wb2.Close
    Kill FilePath & FileName & xFile
    Set OutlookMail = Nothing
    Set OutlookApp = Nothing
    Ws.Delete
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    End Sub

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,486

    Re: VBA Macro Sent Range of Cells and Email from a Pick List

    You can get a list of contacts from your outlook account.

    To test it out,
    Create an ActiveX Combobox and an ActiveX Button.
    Add this code to the button.
    Please Login or Register  to view this content.
    Click the button and the combobox should populate with your contacts

  3. #3
    Forum Contributor
    Join Date
    08-29-2014
    Location
    Chicago, IL
    MS-Off Ver
    2014
    Posts
    164

    Re: VBA Macro Sent Range of Cells and Email from a Pick List

    Thanks for the reply, I actually created a lookup and replaced the email address with the following


    .To = ThisWorkbook.Sheets("Combined").Range("w8")

+ 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: 3
    Last Post: 12-08-2016, 10:37 AM
  2. Macro to copy range of cells (2 columns) to outlook email body
    By thobbs in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-09-2016, 12:29 PM
  3. [SOLVED] Macro to automatically email range of cells in picture format
    By jonrack in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-11-2014, 11:10 PM
  4. [SOLVED] edit a macro that will limit the range of cells being copied in the email body
    By melody10 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-16-2013, 10:45 AM
  5. [SOLVED] Excel Macro To Create A New Email With A Range of Cells Included in the body
    By RickN85 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-05-2012, 05:49 PM
  6. Macro to pick up item from list
    By Saky in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 11-18-2010, 11:28 AM
  7. Replies: 1
    Last Post: 06-27-2005, 07:05 AM

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