你好,
請嘗試以下代碼
Private Sub Worksheet_Change(ByVal Target As Range)
Dim xRg As Range
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Range("c:c"), Target) Is Nothing Then Exit Sub
If Target.Value = "done" Then
Set xRg = Target.Offset(0, -1) 'Find email address
Call Mail_small_Text_Outlook(xRg.Value)
End If
End Sub
Sub Mail_small_Text_Outlook(ByVal xTo As String)
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "Hi there" & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
"This is line 2"
On Error Resume Next
With xOutMail
.To = xTo
.CC = ""
.BCC = ""
.Subject = "send by cell value test"
.Body = xMailBody
.Display 'or use
' .Send
End With
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
您提到您想向 PM 發送一封電子郵件,其首字母與標記為已完成的同一行相同。 他/她的電子郵件地址是否在同一行? 第 6 行的代碼有助於找到項目經理的姓名首字母,您可以更改它以使其找到電子郵件地址。
請將第 5 行中的字符串“done”更改為您用來標記作業已完成的實際字符串。
請注意,您可以根據需要更改下面的代碼段。
xMailBody = "你好" & vbNewLine & vbNewLine & _
“這是第 1 行” & vbNewLine & _
“這是第 2 行”
在錯誤恢復下一頁
使用 xOutMail
.To = xTo
.CC =“”
.BCC =“”
.Subject =“通過單元格值測試發送”
.Body = xMailBody
.display '或使用
' 。發送
結束
如果您有任何問題,請隨時問我。
阿曼達