email spreadsheet macro

biglb79

Active Member
Joined
Oct 17, 2007
Messages
299
hello, does anyone know how to write a macro that would email out a spreadsheet for all the emails listed in column N on that specific tab? also, does it matter if some emails are listed twice as some people handle more than one entity?
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
it should send entire spreadsheet to everyone listed in column N in one email or in a seperate emails?
 
Upvote 0
this should send spreadsheet as attachment:

VBA Code:
Sub test()
    Dim lastRow As Long
    Dim recipients As String
    Dim WB As Workbook
    Dim oApp As Object, oMail As Object
   
    Application.ScreenUpdating = False
       
    With ActiveSheet
        lastRow = .Cells(.Rows.Count, "n").End(xlUp).Row
        For i = 2 To lastRow
            recipients = ";" & .Range("n" & i).Value
        Next i
    End With
    
    Set WB = ActiveWorkbook
    Set oApp = CreateObject("Outlook.Application")
    Set oMail = oApp.CreateItem(0)
    With oMail
        .to = recipients
        .Subject = "test subject"
        .HTMLBody = "test body" & .HTMLBody
        .Attachments.Add WB.FullName
        .Display
    End With
   
    Set oMail = Nothing
    Set oApp = Nothing

    Application.ScreenUpdating = True
End Sub
 
Upvote 0
so, is there a way to adjust this and only send the current tab instead of including all the tabs in the worksheet? also it only had one email address in the email instead of the 16 that are listed
 
Upvote 0
Try this
VBA Code:
Sub MM1()
 Dim lastRow As Long, recipients As String, WB As Workbook
 Dim oApp As Object, oMail As Object, i As Long, filename As String
 ActiveSheet.Copy
 Set WB = ActiveWorkbook
 filename = WB.Worksheets(1).Name
 On Error Resume Next
 Kill "C:\temp\" & filename
 On Error GoTo 0
 WB.SaveAs filename:="C:\temp\" & filename
    Application.ScreenUpdating = False
 With ActiveSheet
     lastRow = .Cells(.Rows.Count, "n").End(xlUp).Row
     For i = 2 To lastRow
         recipients = recipients & ";" & .Range("n" & i).Value
     Next i
 End With
 
 Set WB = ActiveWorkbook
 Set oApp = CreateObject("Outlook.Application")
 Set oMail = oApp.CreateItem(0)
 With oMail
     .To = recipients
     .Subject = "test subject"
     .HTMLBody = "test body" & .HTMLBody
     .Attachments.Add WB.FullName
     .Display
 End With

 Set oMail = Nothing
 Set oApp = Nothing

 Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Try this
VBA Code:
Sub MM1()
Dim lastRow As Long, recipients As String, WB As Workbook
Dim oApp As Object, oMail As Object, i As Long, filename As String
ActiveSheet.Copy
Set WB = ActiveWorkbook
filename = WB.Worksheets(1).Name
On Error Resume Next
Kill "C:\temp\" & filename
On Error GoTo 0
WB.SaveAs filename:="C:\temp\" & filename
    Application.ScreenUpdating = False
With ActiveSheet
     lastRow = .Cells(.Rows.Count, "n").End(xlUp).Row
     For i = 2 To lastRow
         recipients = recipients & ";" & .Range("n" & i).Value
     Next i
End With

Set WB = ActiveWorkbook
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(0)
With oMail
     .To = recipients
     .Subject = "test subject"
     .HTMLBody = "test body" & .HTMLBody
     .Attachments.Add WB.FullName
     .Display
End With

Set oMail = Nothing
Set oApp = Nothing

Application.ScreenUpdating = True
End Sub
that works! thanks so much!!!
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,613
Members
449,090
Latest member
vivek chauhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top