Hi, laduk,
because you choose to have a code for each sheet invdividually and did not take care to refer to each sheet when getting any cell´s information. If you do not use the correct syntax the data will be taken from the active sheet (and not the desired one).
I´d have a go with this (untested as no Outlook available for me for the time being):
Sub Workbook_Open()
procMail "Sheet1"
procMail "Sheet2"
End Sub
Sub procMail(strSheet As String)
Dim strSub As String
Dim strBody As String
Dim strTo As String
Dim strCC As String
Dim strBCC As String
Dim ws As Worksheet
Dim i As Long
Dim OutApp As Object
Dim OutMail As Object
Set ws = Sheets(strSheet)
For i = 2 To ws.Range("A" & Rows.Count).End(xlUp).Row
If ws.Cells(i, 3).Value <= Date And ws.Cells(i, "E") = "" Then
ws.Cells(i, "E") = Now
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
With Sheets("sheet3")
strTo = Join(Application.Transpose(.Range("email")), ";")
strCC = "" '.Cells(i, 4).Value
strBCC = ""
strSub = "Expiry Notice"
strBody = "Hi there," & vbNewLine & vbNewLine & _
ws.Cells(i, 1).Value & " " & _
" number 1 message" & " " & _
"yes please" & " " & ws.Cells(i, 3).Value & "." & _
vbCrLf & vbCrLf & "Thank you."
End With
With OutMail
.To = strTo
.CC = strCC
.BCC = strBCC
.subject = strSub
.body = strBody
.Send
End With
Set OutMail = Nothing
Set OutApp = Nothing
End If
Next i
End Sub
Ciao,
Holger
Bookmarks