使用Excel中的macros在单个邮件中发送多个工作表中的详细信息

每当我运行一个macros,我需要发送一定的范围的单元格在不同的工作表特定的邮件ID。

Sub Send_Range() Sheet1.Range("A2:V28").Select ActiveWorkbook.EnvelopeVisible = True With ActiveSheet.MailEnvelope ' .Introduction = "This is a sample worksheet." .Item.To = "pkumar11@amgen.com" .Item.Subject = "My subject" .Item.Send End With End Sub 

使用这段代码,我可以在邮件中发送来自工作表1的范围(A2:V28)的所有值。 但是我也希望在单张邮件中发送来自工作表2的范围值(B3:F28)以及工作表1中的值。 请帮帮我。

你可以使用Ron de Bruin编写的函数,允许你将范围转换成HTML:

 Sub SendRange() Dim mailApp As Object, mail As Object Dim rng As Range, rng1 As Range Set mailApp = CreateObject("Outlook.Application") Set mail = mailApp.createitem(0) Set rng = Sheets("Sheet1").Range("A2:V28").SpecialCells(xlCellTypeVisible) Set rng1 = Sheets("Sheet2").Range("B3:F23").SpecialCells(xlCellTypeVisible) With mail .To = "pkumar11@amgen.com" .Subject = "My subject" .HTMLBody = RangetoHTML(rng) & "<br>" & RangetoHTML(rng1) .display End With End Sub Function RangetoHTML(rng As Range) ' Changed by Ron de Bruin 28-Oct-2006 ' Working in Office 2000-2016 Dim fso As Object Dim ts As Object Dim TempFile As String Dim TempWB As Workbook TempFile = Environ$("temp") & "\" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm" 'Copy the range and create a new workbook to past the data in rng.Copy Set TempWB = Workbooks.Add(1) With TempWB.Sheets(1) .Cells(1).PasteSpecial Paste:=8 .Cells(1).PasteSpecial xlPasteValues, , False, False .Cells(1).PasteSpecial xlPasteFormats, , False, False .Cells(1).Select Application.CutCopyMode = False On Error Resume Next .DrawingObjects.Visible = True .DrawingObjects.Delete On Error GoTo 0 End With 'Publish the sheet to a htm file With TempWB.PublishObjects.Add( _ SourceType:=xlSourceRange, _ Filename:=TempFile, _ Sheet:=TempWB.Sheets(1).Name, _ Source:=TempWB.Sheets(1).UsedRange.Address, _ HtmlType:=xlHtmlStatic) .Publish (True) End With