我正在尝试获取一个宏,以发送粘贴到电子邮件正文中的不同范围的电子邮件
从下面的代码中可以看到,这成功地向选定的目标对象发送了一封电子邮件,其中包含选定的范围。
现在我需要尝试更改
ActiveSheet.Range("B8:D304").Select
还要在另一张“ Ticket Tracker”工作表上选择一个相似的范围,并将其放在底部或电子邮件中的任何位置。
我尝试自己搜索结果,但是由于我从未接受过.vba培训并且从基本信息中将这些内容拼凑起来,因此我自己无法很好地理解这一点。
我尝试了联盟,但发现它们不会影响多张纸。
Sub SendTrackerForEmails()
' Select the range of cells on the active worksheet.
ActiveSheet.Range("B8:D304").Select
' Show the envelope on the ActiveWorkbook.
ActiveWorkbook.EnvelopeVisible = True
' Set the optional introduction field thats adds
' some header text to the email body. It also sets
' the To, CC and Subject lines.
With ActiveSheet.MailEnvelope
.Introduction = ""
.Item.To = Range("F17").Value
.Item.Subject = Worksheets("Splash Screen").Range("H10").Value & "'s
Email Tracker Results"
.Item.CC = Range("F26").Value & ";" & Range("H9").Value
End With
End Sub
我不确定“票务追踪器”中的第二个范围是否会放入电子邮件中,尽管我不确定如何选择。
我尝试了以下答案,但是如果您阅读注释,则在尝试隐藏错误时会导致错误消息。
似乎与邮件信封打开的事实有关。
答案 0 :(得分:1)
一个不错的解决方法是:
参见下文:
Sub SendTrackerForEmails()
Dim dataSheet As Worksheet: Set dataSheet = ActiveSheet
Dim newSheet As Worksheet
Dim ticketSheet As Worksheet: Set ticketSheet = ThisWorkbook.Worksheets("Ticket Tracker")
' insert a new sheet
With ThisWorkbook
Set newSheet = .Sheets.Add(After:=.Worksheets(.Worksheets.Count))
End With
' copy data from 2 sheets
dataSheet.Range("B8:D304").Copy newSheet.Range("A1")
ticketSheet.Range("B8:D304").Copy newSheet.Range("A300")
' Show the envelope on the Workbook
newSheet.Activate
ThisWorkbook.EnvelopeVisible = True
' Set the optional introduction field thats adds
' some header text to the email body. It also sets
' the To, CC and Subject lines.
With newSheet.MailEnvelope
.Introduction = ""
.Item.To = dataSheet.Range("F17").Value
.Item.Subject = ThisWorkbook.Worksheets("Splash Screen").Range("H10").Value & "'s Email Tracker Results"
.Item.CC = dataSheet.Range("F26").Value & ";" & dataSheet.Range("H9").Value
.Send ' added this
End With
' added this
ThisWorkbook.EnvelopeVisible = False
Application.DisplayAlerts = False
newSheet.Delete
Application.DisplayAlerts = True
End Sub