[英]Copy tabs in to a new unopened file and send in email with text in body and subject - VBA - Macro
have a segment of code that attaches copy tabs from a document and pastes them into a new document.有一段代码附加文档中的复制选项卡并将它们粘贴到新文档中。 Then sends only the new document to the intended addressees.
然后只将新文档发送给预期的收件人。
Is there a way I can change the name of the file I'm intending to send?有什么方法可以更改我打算发送的文件的名称? It just sends as Book1.
它只是作为 Book1 发送。
Additionally, I'd like to add text in the body and the subject header of the email too.此外,我还想在正文和电子邮件的主题标题中添加文本。 How can I go about doing this?
我该怎么做呢?
Sub Sendtabonemail()
Dim wb As Workbook
Dim strbody As String
Set wb = Workbooks.Add
ThisWorkbook.Sheets("sheet6").Copy After:=wb.Sheets(1)
ThisWorkbook.Sheets("sheet3").Copy After:=wb.Sheets(1)
wb.Application.Dialogs(xlDialogSendMail).Show "" & "emailreceiver1@domain.com" & "; " & "emailreceiver2@domain.com"
End Sub
It's calling it Book1
because that's the default name for a new workbook until it's saved.它称它为
Book1
,因为这是新工作簿保存前的默认名称。 To name it, just save the file to a temporary location (with a name of your choosing) before sending.要命名它,只需在发送前将文件保存到一个临时位置(使用您选择的名称)。
wb.SaveAs "C:\temporary folder location\filename_to_use.xlsx"
Sub dfjero()
Dim newWBname As String
newWBname = Sheets(1).Name & "_" & Month(Date) & "_" & Day(Date) & "_" & Year(Date)
Workbooks.Add
If Len(Dir("c:\newFile", vbDirectory)) = 0 Then ' create and delete temporary directory and file
MkDir "c:\newFile"
ActiveWorkbook.SaveAs Filename:="C:\newFile\" & newWBname & ".xls", FileFormat:=xlExcel8
' This is where you send the book via email
ActiveWorkbook.Close
On Error Resume Next
Kill "C:\newFile\" & newWBname & ".xls"
RmDir "C:\newFile\"
On Error GoTo 0
Else ' or add file to already created directory
ActiveWorkbook.SaveAs Filename:="C:\newFile\" & newWBname & ".xls", FileFormat:=xlExcel8
' or alternatively this is where you send the workbook via email
End If
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.