本文介绍了如何在邮件正文中复制粘贴excel表并使用vbscript发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 如何在邮件正文中复制粘贴excel表并使用vbscript发送邮件 我有Excel表格,我需要通过电子邮件发送此表格。 /> i在vba中试过但是在vbscript我无法做到 需要帮助.. !! 我尝试了什么: On Error Resume Next 设置rng =表格(sheet2)。范围(D2:L9)。SpecialCells(xlCellTypeVisible) 错误GoTo清理 Set OutMail = OutApp.CreateItem(0) On Error Resume Next With OutMail .To =vijaysinh.d@tcs。 com .Subject =补救票状态 .HTMLBody = StrBody& RangetoHTML(RNG) .Attachments.Add( Z:\21 Warroom 1\Open票务Dump\2019\May\24 May\data\Impact_Sheet_CRQ000000095836.xls) 。发送 结束 错误GoTo 0 Set OutMail = Nothing 清理: Set OutApp = Nothing Application.ScreenUpdating = True 结束次级 功能RangetoHTML(按范围而定) '由Ron de Bruin改变2006年10月28日 '在办公室工作2000-2013 Dim fso As Object Dim ts As Object Dim TempFile As String Dim TempWB As Workbook TempFile = Environ $(temp )& \&格式(现在,dd-mm-yy h-mm-ss)& .htm '复制范围并创建一个新工作簿来过去数据 rng.Copy 设置TempWB = Workbooks.Add(1) 使用TempWB.Sheets(1) 。细胞(1).PasteSpecial膏:= 8 .Cells(1).PasteSpecial xlPasteValues,FALSE,FALSE .Cells(1).PasteSpecial xlPasteFormats,FALSE,FALSE 。细胞(1)。选择 Application.CutCopyMode = False On Error Resume Next .DrawingObjects.Visible = True .DrawingObjects.Delete 错误GoTo 0 结束 '将工作表发布到htm文件 使用TempWB.PublishObjects.Add(_ SourceType:= xlSourceRange,_ 文件名:= TempFile,_ 工作表:= TempWB.Sheets(1).Name,_ 来源:= TempWB.Sheets(1) .UsedRange.Address,_ HtmlType:= xlHtmlStatic) 。发布(True) 结束 '将htm文件中的所有数据读入RangetoHTML 设置fso = CreateObject(Scripting.FileSystemObject) 将TS = fso.GetFile(临时文件).OpenAsTextStream(1,-2) RangetoHTML = ts.readall ts.Close RangetoHTML =替换(RangetoHTML,align = center x:publishsource =,_ align = left x:publishsource =) '关闭TempWB TempWB.Close savechanges:= False '删除我们在此函数中使用的htm文件 杀死TempFile 设置ts =没有什么 设置fso =没什么 设置TempWB =没什么 结束功能解决方案 (temp)&a熔点; \&格式(现在,dd-mm-yy h-mm-ss)& .htm '复制范围并创建一个新工作簿来过去数据 rng.Copy 设置TempWB = Workbooks.Add(1) 使用TempWB.Sheets(1) 。细胞(1).PasteSpecial膏:= 8 .Cells(1).PasteSpecial xlPasteValues,FALSE,FALSE .Cells(1).PasteSpecial xlPasteFormats,FALSE,FALSE 。细胞(1)。选择 Application.CutCopyMode = False On Error Resume Next .DrawingObjects.Visible = True .DrawingObjects.Delete 错误GoTo 0 结束 '将工作表发布到htm文件 使用TempWB.PublishObjects.Add(_ SourceType:= xlSourceRange,_ 文件名:= TempFile,_ 工作表:= TempWB.Sheets(1).Name,_ 来源:= TempWB.Sheets(1) .UsedRange.Address,_ HtmlType:= xlHtmlStatic) 。发布(True) 结束 '将htm文件中的所有数据读入RangetoHTML 设置fso = CreateObject(Scripting.FileSystemObject) 将TS = fso.GetFile(临时文件).OpenAsTextStream(1,-2) RangetoHTML = ts.readall ts.Close RangetoHTML =替换(RangetoHTML,align = center x:publishsource =,_ align = left x:publishsource =) '关闭TempWB TempWB.Close savechanges:= False '删除我们在此函数中使用的htm文件 杀死TempFile 设置ts =没有什么 设置fso =没什么 设置TempWB = Nothing 结束功能 How to copy paste excel table in mail body and send mail using vbscriptI have excel sheet table and i need to send this table in email.i tried in vba but in vbscript i unable to doNeed help..!!What I have tried:On Error Resume Next Set rng = Sheets("sheet2").Range("D2:L9").SpecialCells(xlCellTypeVisible) On Error GoTo cleanup Set OutMail = OutApp.CreateItem(0) On Error Resume Next With OutMail .To = "[email protected]" .Subject = "Remedy ticket status" .HTMLBody = StrBody & RangetoHTML(rng) .Attachments.Add ("Z:\21 Warroom 1\Open Ticket Dump\2019\May\24 May\data\Impact_Sheet_CRQ000000095836.xls") .Send End With On Error GoTo 0 Set OutMail = Nothingcleanup: Set OutApp = Nothing Application.ScreenUpdating = TrueEnd SubFunction RangetoHTML(rng As Range)' Changed by Ron de Bruin 28-Oct-2006' Working in Office 2000-2013 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 'Read all data from the htm file into RangetoHTML Set fso = CreateObject("Scripting.FileSystemObject") Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2) RangetoHTML = ts.readall ts.Close RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _ "align=left x:publishsource=") 'Close TempWB TempWB.Close savechanges:=False 'Delete the htm file we used in this function Kill TempFile Set ts = Nothing Set fso = Nothing Set TempWB = NothingEnd Function 解决方案 ("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 'Read all data from the htm file into RangetoHTML Set fso = CreateObject("Scripting.FileSystemObject") Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2) RangetoHTML = ts.readall ts.Close RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _ "align=left x:publishsource=") 'Close TempWB TempWB.Close savechanges:=False 'Delete the htm file we used in this function Kill TempFile Set ts = Nothing Set fso = Nothing Set TempWB = NothingEnd Function 这篇关于如何在邮件正文中复制粘贴excel表并使用vbscript发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 阿里云证书,YYDS! 05-22 18:47