Excel VBA를 사용하여 대량 메일 보내기

Excel VBA를 사용하여 대량 메일 보내기

조건이 충족되면 다른 사람들에게 대량 메일을 보내는 프로젝트를 진행하고 있었습니다.

조건 :

  • U 열에는 최종 상태(미결 또는 WIP)가 포함됩니다(현재 날짜가 더 길더라도 마감된 경우 전송되지 않음).
  • Q 열에는 마감 날짜가 포함되어 있습니다. 현재 날짜와 비교할 때 자동 촬영이 사람들에게 메일을 보내는 것보다 적습니다.

for 루프를 사용하려고 시도했지만 동일한 To 및 CC를 사용하여 4개의 메일을 촬영하게 되었습니다. 그리고 비교할 다음 행으로 이동하지 않습니다.

셀 V2를 Q2와 비교한 후 다음 루프 V3을 Q3과 비교하고 동시에 셀 U2에 "Open"이 있는지 확인합니다.

미리 감사드립니다.

아래와 같이 코드를 작성하세요:

Sub Data_RoundedRectangle1_Click()

Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object
Dim StrBody As String



On Error Resume Next

For i = 1 to 4

If Sheets("Data").Range("U2:U6").Value2 = "Open" Or     Sheets("Data").Range("U2:U6").Value2 = "WIP" And (CDate(Cells(2, 17).Value) <     Now()) Then



        Set rng = Nothing
        On Error Resume Next
        'Only the visible cells in the selection
        Set rng = Selection.SpecialCells(xlCellTypeVisible)
        'You can also use a fixed range if you want
        Set rng = Sheets("Checklist").Range("A2:B25").SpecialCells(xlCellTypeVisible)
        On Error GoTo 0


        With Application
        .EnableEvents = False
        .ScreenUpdating = False
        End With

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

        On Error Resume Next

With OutMail


        If Worksheets("Data").Cells(i, "C").Value2 = "Operation_Support" And Worksheets("Data").Cells(i, "E").Value2 = "Quality_Assurance" Then


     StrBody = "Hi," & "<br>" & _


.To = "a"

.CC = "b"
.BCC = ""
.Subject = ""
.HTMLBody = StrBody & RangetoHTML(rng)
.Attachments.Add ActiveWorkbook.FullName
' You can add other files by uncommenting the following line.
'.Attachments.Add ("C:\test.txt")
.Display
'.Send

ElseIf Worksheets("Data").Cells(i, "C").Value = "Operation_Support" And Worksheets("Data").Cells(i, "E").Value = "Analytics" Then

StrBody = "Hi," & "<br>" & _
      "PFB the process details which requires your attention." & "<br>" & _
      "The review for this process has crossed over due." & "<br>" & _
      "Please ask the process owner to review the Process Manuals and Maps."     & "<br><br><br>"

.To = "c"

.CC = "d"
.BCC = ""
.Subject = "Process Manual and Maps Review is Overdue"
.HTMLBody = StrBody & RangetoHTML(rng)
.Attachments.Add ActiveWorkbook.FullName
' You can add other files by uncommenting the following line.
'.Attachments.Add ("C:\test.txt")
.Display
'.Send

End If

    End With

    i = i + 1
    Exit For

    End If
End If

Next r

On Error GoTo 0

With Application
    .EnableEvents = True
    .ScreenUpdating = True
End With

Set OutMail = Nothing
Set OutApp = Nothing

Next x
End Sub

여기에 이미지 설명을 입력하세요

답변1

내 생각엔 너의 루프 때문인 것 같아

For i = 1 to 4

하지만 당신은 을 참조한 적이 없어서 i그렇게 되고 있습니다.모든 것네번. 대신 이렇게 사용해야합니다 -

If Sheets("Data").cells(21,1+i).Value2 = "Open" Or Sheets("Data").cells(21,1+i).Value2 = "WIP" And ...

if두 번째 부분이 무엇을 말하는지 잘 모르겠지만 요점은 알 수 있습니다.

관련 정보