【发布时间】:2022-01-10 04:43:09
【问题描述】:
感谢您抽出宝贵时间帮助我完成这个项目。
我有一些 vba 可以向我的电子表格上的每个收件人发送一封电子邮件,并在电子表格的文本信息的正文中包含。这段代码效果很好。这是我被卡住的部分......
工作簿包含几个表格,我想过滤并复制/粘贴到每封电子邮件中,但每个表格中的数据需要过滤为适用于每个收件人的数据。
例如: 该电子邮件正在发送给区域领导者,其中包括他们所在区域的整体分数。 我有 1 个表格,其中包含可以按区域过滤的经理分数和 在第二个选项卡上,我为每个区域提供了一个表格,该表格按服务类型向下钻取分数。
因此,对于西南地区负责人,我想过滤表 1 以仅显示西南地区的经理,将该表直接复制/粘贴到电子邮件中,然后转到服务类型表并复制西南表并粘贴进入电子邮件。
我想要完成的最后一项工作是将位于单独选项卡上的员工级别详细信息复制到工作簿并将其附加到电子邮件中。这也需要针对每个地区的员工。
我不知道这是否可以在我的代码中实现,或者是否有一种聪明的方法来完成它。感谢您愿意提供的任何帮助或见解!我附上了一个示例文件,下面是我当前使用的电子邮件代码。我还有一些代码可以根据可能有用也可能没有帮助的区域过滤数据。
Sub SendMailtoRFE()
Dim outapp As New Outlook.Application
Dim outmail As Outlook.Mailitem
Dim wks As Worksheet
Dim i As Integer
Dim sFile1 As String
Dim TempFilePath As String
Environ ("UserProfile")
Set outapp = CreateObject("outlook.application")
sFile1 = "Infographic"
TempFilePath = Environ$("temp") & "Roadside Assistance " 'FIND OUT HOW TO CLEAN UP THE NAME: "Temp" added to file name
ActiveWorkbook.Sheets(sFile1).ExportAsFixedFormat Type:=xlTypePDF, Filename:=TempFilePath & sFile1 & ".pdf"
On Error Resume Next
For i = 3 To wks.Range("A" & Rows.Count).End(xlUp).Row
Set outmail = outapp.CreateItem(olMailItem)
With outmail
.To = wks.Range("C" & i).Value
.Subject = wks.Range("A" & i).Value & " Region Roadside Assistance YTD Communication"
.HTMLBody = "Dear " & wks.Range("C" & i).Value & "," & "<br></br>" & _
"You've shared how important Roadside Assistance is for your personal auto clients. As one of the highest frequency types of losses, success or failure " & _
"here may be seen as a signal of the overall value of the program." & "<br></br><br></br>" & _
"Here are the results for clients in your area who completed a survey. Year to date, the NPS was " & FormatPercent(wks.Range("K" & i).Value, 0) & _
" based on " & wks.Range("H" & i).Value & " total responses." & _
" The overall score for all regions is " & FormatPercent(wks.Range("K12").Value, 0) & "." & "<br></br><br></br>" & _
"Below are a few additional details to help you understand your region's score. " & _
"Please follow up with any questions or concerns." & "<br></br><br></br>" & vbNewLine & _
"**Please note, the table containing MLGA scores shows only the MLGA's where 5 or more survey responses were received.**"
.Attachments.Add (TempFilePath & sFile1 & ".pdf")
.display
End With
On Error GoTo 0
Set outmail = Nothing
Next i
Set outapp = Nothing
End Sub
''Filter Region on the MLGA Tow NPS Score Tab
Sub FilterSouthWest()
Dim wks As Worksheet
Set wks = Sheets("MLGA TOW NPS Score")
With wks.Range("A2:C2")
.AutoFilter Field:=3, Criteria1:="9A"
End With
End Sub
【问题讨论】: