Hi Logit-Sorry for the delay in getting back to you.
All the workbooks have been named with the supplier name in the front of it. The supplier email address are in a different workbook. I am not following your comment on "Have the supplier email address (before the @ symbol) the same as the workbook name."
I have pasted the script that I am working with. Please let me know if you see any gaps. I have been watching videos and adding some of this stuff.
This is one of the suppliers and email address from the supplier list work book:
[TABLE="width: 1247"]
<colgroup><col><col><col><col><col><col></colgroup><tbody>[TR]
[TD]VNAME[/TD]
[TD]VNDNO[/TD]
[TD]BUYER CODE[/TD]
[TD]BUYER NAME[/TD]
[TD]SUPPLIER CONTACT NAME[/TD]
[TD]SUPPLIER CONTACT E-MAIL[/TD]
[/TR]
[TR]
[TD]ULINE INC[/TD]
[TD]880800[/TD]
[TD]JM[/TD]
[TD]John Miller[/TD]
[TD]N/A[/TD]
[TD]customer.service@uline.com [/TD]
[/TR]
</tbody>[/TABLE]
The weekly workbook that I am trying to send out will be saved as ULINE INC 110518 for this week. The date will change weekly.
Script:
Sub Script_for_sending_emails()
Dim wb1 As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim FileExtStr As String
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set wb1 = ActiveWorkbook
'Make a copy of the file/Open it/Mail it/Delete it
'If you want to change the file name then change only TempFileName
TempFilePath = Environ$("temp") & ""
TempFileName = "Copy of " & wb1.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")
FileExtStr = "." & LCase(Right(wb1.Name, Len(wb1.Name) - InStrRev(wb1.Name, ".", , 1)))
wb1.SaveCopyAs TempFilePath & TempFileName & FileExtStr
Dim OutApp As Object
Dim OutMail As Object
'To run in a loop until the end of the email sheet
Dim i As Long
For i = 2 To Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
'.To = ""
'---------------------------------------------------
.To = ActiveWorkbook.Sheets("Sheet1").Range("C1").Value
'-----------------
'.To = "GroupName"
'-----------------
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.Body = "Hi there"
'.Attachments.Add TempFilePath & TempFileName & FileExtStr
.Attachments.Add "C:\Users\BJoseph\Desktop\Mail Merge testing\Exception report verbiage.docx"
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.Display
.Send 'or use .Display
End With
On Error GoTo 0
'------------------------------------------------------------------------------
' The receiver can see the original mail address in the properties.
'.SentOnBehalfOfName = """John DOe"" <JohnDoe@yahoo.com>"
'-------------------------------------------------------------------------------
'Delete the file
Kill TempFilePath & TempFileName & FileExtStr
Set OutMail = Nothing
Set OutApp = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
I do not know how to put the LEFT function in this mix and then do the loop to send the email. Let me know if you need more details. I feel as though I am doing a poor job explaining this.