下面的VBA
會向多個用戶發送電子郵件,但只有第一個收件人才能收到正確的電子郵件。因此,如果A列中有10個地址,那麼地址1將會得到正確的電子郵件,其他所有人都會得到For
這個詞,而不是別的。我不知道如何解決它,但認爲這是抵消?謝謝 :)。括號excel電子郵件VBA適用於一個收件人並非全部
正確的電子郵件是數據從
**For 10/21/2015** (Msg = "For " & c.Offset(, 1) & Chr(14) & Chr(14)
**-There are no issues to report in the HLA & Molecular Diagnostics Laboratory.** ( For i = 3 To 14
If LCase(WS.Cells(c.Row, i)) = "x" Then
Msg = Msg & " -" & WS.Cells(1, i) & Chr(14)
End If
Next)
VB
拉Private Sub CommandButton1_Click()
Dim WS As Worksheet, Rng As Range, c As Range
Dim OutApp As Object, OutMail As Object
Dim Msg As String, Addr As String, FName As String, i As Long
Dim obj As Object
Dim MyFile As String, MyFileCopy As String
'define path
MyFileCopy = "L:\NGS\HLA LAB\total quality management\QC & QA\DOSE reports\DOSE reporting form Attachment.xlsx"
'create a separate sheet2 to mail out
Sheets(2).Copy
Set wkb = ActiveWorkbook
With wkb
.SaveAs MyFileCopy
.Close True
End With
' create connection, check condition, send email
Set OutApp = CreateObject("Outlook.Application")
Set WS = ThisWorkbook.Sheets("Email")
With WS
Set Rng = .Range("A2", .Range("A" & .Rows.Count).End(xlUp))
End With
For Each c In Rng
Msg = "For " & c.Offset(, 1) & Chr(14) & Chr(14)
For i = 3 To 14
If LCase(WS.Cells(c.Row, i)) = "x" Then
Msg = Msg & " -" & WS.Cells(1, i) & Chr(14)
End If
Next
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = c.Offset(, 0)
.CC = ""
.BCC = ""
.Subject = "Daily Operational Safety Briefing"
.Body = Msg
If LCase(c.Offset(, 3)) = "x" Then .Attachments.Add MyFileCopy, 1
.Send
End With
Next c
'confirm message sent and delete copy
MsgBox "The data has been emailed sucessfully.", vbInformation
Kill MyFileCopy
Set OutMail = Nothing
Set OutApp = Nothing
' Exit and do not save
Application.Quit
ThisWorkbook.Close SaveChanges:=False
End Sub
不知道,如果我得到你的權利,但是你的消息文本是否在每一行的B列中,還是僅在B2中? – therak
「For」後面的日期在B2中,下一行的註釋來自C2或D2。數據總是來自這些單元格。所以即使有10個電子郵件地址B2,C2或D2也會被使用。取決於'x'決定使用的評論。謝謝 :)。 – Chris