将选项卡复制到一个新的未打开的文件中,并在电子邮件中发送 body 中的文本和主题 - VBA - 宏
Copy tabs in to a new unopened file and send in email with text in body and subject - VBA - Macro
有一段代码可以附加文档中的复制标签并将其粘贴到新文档中。然后只将新文档发送给预期的收件人。
有什么方法可以更改我要发送的文件的名称?它只是作为 Book1 发送。
此外,我还想在 body 和电子邮件的主题 header 中添加文本。我该怎么做呢?
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
之所以将其命名为 Book1
,是因为这是新工作簿保存前的默认名称。要命名它,只需在发送前将文件保存到一个临时位置(使用您选择的名称)。
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
有一段代码可以附加文档中的复制标签并将其粘贴到新文档中。然后只将新文档发送给预期的收件人。
有什么方法可以更改我要发送的文件的名称?它只是作为 Book1 发送。
此外,我还想在 body 和电子邮件的主题 header 中添加文本。我该怎么做呢?
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
之所以将其命名为 Book1
,是因为这是新工作簿保存前的默认名称。要命名它,只需在发送前将文件保存到一个临时位置(使用您选择的名称)。
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