Generate Email

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,341
Office Version
  1. 365
Platform
  1. Windows
I have the code below that is meant to create one email and populate the that email with data from the excel workbook.

Can this code be modified so that it looks down a column in a table and if row says "SharePoint" it creates a new email each time using the data from the applicable row?

The data/table is on a tab named SharePoint. The table Name is SharePointTable The table start in B31 (headers)
Need it to look down column B for "SharePoint"

The applicable data for the emails is still coming from columns D and C of each row in the table


Thank you very much for the time and help. Greatly appreciated.

code that needs to be modified:

Code:
Option Explicit

Sub Mail_workbook_Outlook()

    Dim OutApp As Object
    Dim OutMail As Object


    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    


    On Error Resume Next
    With OutMail
        .to = "gregory.heyman@DRS.com"
        .CC = ""
        .BCC = ""
        .Subject = "#" & Sheets("Step 7").Range("D31").Text & "#" & "   " & Sheets("Step 7").Range("C31").Text
        .Body = "This email will generate a new folder in Sharepoint and save this workbook there." & vbNewLine & vbNewLine & "You may add additional attachments, that you want saved to this Quote folder. " & vbNewLine & vbNewLine & "The         Folder will be named after the Source ID (The email Subject)" & vbNewLine & vbNewLine & "  " & vbNewLine & vbNewLine & "PLEASE DO NOT CHANGE THE SUBJECT NAME"
        .Attachments.Add (Application.ActiveWorkbook.FullName)
       
        '.Send
        .display
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
I think you mean something like this

VBA Code:
Sub jec()
 Dim it
 For Each it In Sheets("SharePoint").ListObjects("SharePointTable").DataBodyRange.Columns(2).Cells
   If it.Value = "SharePoint" Then
      With CreateObject("outlook.application").createitem(0)
        .to = "test@gmail.com"
        .Subject = ""
        .body = it.Offset(, 2) & "---" & it.Offset(, 1)
        .attachments.Add ThisWorkbook.FullName
        .display  '.send
     End With
   End If
 Next
End Sub
 
Upvote 0
Solution
Thank you!

Here is what I ended up with. It works but seems very slow.

Code:
Sub Create_Email()

Dim SPCount


'If SPCount < 3 Then Exit Sub

 For Each SPCount In Sheets("SharePoint").ListObjects("SharePointTable").DataBodyRange.Columns(1).Cells
  
   If SPCount.Value = "SharePoint" Then
      With CreateObject("outlook.application").createitem(0)
        .to = "gregory.heyman@DRS.com"
        .CC = ""
        .BCC = ""
        .Subject = "#" & SPCount.Offset(, 2) & "#" & "  " & SPCount.Offset(, 1)
        .body = "SharePoint Folder Name: " & SPCount.Offset(, 2) & vbNewLine & vbNewLine & "Vendor: " & SPCount.Offset(, 1) & vbNewLine & vbNewLine & "This email will generate a new folder in SharePoint and save this workbook there." & vbNewLine & vbNewLine & "You may add additional attachments, that you want saved to this Quote folder. " & vbNewLine & vbNewLine & "The Folder will be named after the Cost Source ID (The email Subject)" & vbNewLine & vbNewLine & "  " & vbNewLine & vbNewLine & "PLEASE DO NOT CHANGE THE EMAIL SUBJECT"
        .attachments.Add ThisWorkbook.FullName
        .display
     End With
   End If
   
 Next


End Sub
 
Upvote 0
Yes it is slow because it creates individual emails for every row.

You are welcome!(y)
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,845
Members
449,051
Latest member
excelquestion515

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