我目前正在处理小型excel“数据库”,因为其中一列中的单元格可以由多个人编辑。可以编辑的单元格来自下拉菜单。一旦一个人更改了一个或多个单元格,我希望将相应行中的某些数据添加到电子邮件中。最后,在固定的单元格中填充了编辑数据库的人员的姓名缩写,从而发送了电子邮件。
例如 我的A,B和C列是:名称,专业,状态,假设我有10行。然后,通过下拉菜单将“第2行和第7行的状态”单元格从“工作”更改为“休假”。我将姓名缩写添加到固定单元格(例如D1)中,并使用以下内容创建电子邮件:
马克,在假期
斯坦,度假
B列,专业,并不重要,应将其排除在电子邮件之外。
预先感谢
当前(不完整)代码
Private Sub Worksheet_Change(ByVal Target As Range)
Dim xChangeArea As Range
Dim xOutApp As Object
Dim xMailItem As Object
Dim xMailBody As String
On Error Resume Next
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set xChange = Range("$D$1")
Set xChangeArea = Intersect(Target, xChange)
ActiveWorkbook.Save
If Not xChangeArea Is Nothing Then
Set xOutApp = CreateObject("Outlook.Application")
Set xMailItem = xOutApp.CreateItem(0)
xMailBody = "Changes made in document: " & "(A Column Cell) is set to" & "(C column cell)"
With xMailItem
.To = "Email Address"
.Subject = "Worksheet modified in " & ThisWorkbook.FullName
.Body = xMailBody
'.Attachments.Add (ThisWorkbook.FullName)
.Display
End With
Set xChangeArea = Nothing
Set xOutApp = Nothing
Set xMailItem = Nothing
End If
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub