使用Excel VBA将当前Excel作为附件通过Outlook发email给接收人

Sub SendEmail ()
    Dim sRecipient As String
    
    sRecipient = InputBox ("Please input the receipt email address")
    
    
    Dim olApp As Object
    Dim olNameSpace As Object
    Dim olFolder As Object
    Dim olMail As Object
    Set olApp = CreateObject ("Outlook .Application")
    Set olNameSpace = olApp.GetNamespace("MAPI")
    Set olFolder = olNameSpace.GetDefaultFolder(6)
    Set olMail = olApp.CreateItem(0)
    With olMail
        .Subject = "Year 2006 Revenue Chart"
        .Recipients.Add sRecipient
        .Body = "Workbook with chart attached"
        .Attachments.Add ActiveWorkbook.FullName
        .Send
    End With
    
    MsgBox ("Send OK")
End Sub

你可能感兴趣的:(Excel,VBA,excel,email,vba,object,string,input)