我需要excel从打开的工作簿中选择一个特定的工作表,并在每个月末将其发送给特定的收件人。
答案 0 :(得分:0)
这会将打开的工作表保存到指定的路径,并将工作表名称作为文件名,然后为指定的Receiver创建一个Outlook-Mail,并附上新保存的Excel工作表......
Sub SendMail()
Dim Anrede As String, Text1 As String, Text2 As String, path As String, sheetname As String
path = "\\enter\your\path\here\"
sheetname = ActiveSheet.Name
Anrede = "Dear Sir or Madam,"
Text1 = "blablabla"
Text2 = "Kind regards, "
Sheets(sheetname).Copy
ChDir path
ActiveWorkbook.SaveAs Filename:= _
path & sheetname & ".xlsx", FileFormat:= _
xlOpenXMLWorkbook, CreateBackup:=False
Application.ScreenUpdating = False
On Error Resume Next
With CreateObject("Outlook.Application").CreateItem(0)
.To = "mail@adress.here" 'specify receiver mail here, may be a variable too
.Subject = "Your subject here "
.Body = Anrede & vbCrLf & vbCrLf & Text1 & vbCrLf & vbCrLf & Text2
.Attachments.Add path & sheetname & ".xlsx"
.Display 'Or use .Send
End With
End Sub