通过VBA宏(Excel)发送电子邮件

时间:2019-02-27 18:00:54

标签: excel vba outlook outlook-vba

我花了几天的时间试图解决这个问题,我设法阻止了所有错误,但是电子邮件没有显示在我的收件箱中。我试图改变一切,但仍然没有出现。 主要目的是通过按钮将整个工作簿发送到电子邮件(我已将按钮绑定到宏) 无论如何,这是我已经拥有的代码

Sub Send_mail()
Dim OutApp As Object
    Dim OutMail As Object

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next
    With OutMail
        .To = "example@email.com"
        .From = "example@email.com"
        .CC = ""
        .BCC = ""
        .Subject = "Assunto"
        .Body = "Corpo"
        .Attachments.Add ActiveWorkbook.FullName
        .Send

    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub

(ps我确实更改了电子邮件以将其发布,这不是我在代码中所拥有的)

1 个答案:

答案 0 :(得分:1)

请删除.From = "example@email.com" 邮件将带有Outlook默认邮件地址的附件。 在Microsoft文档中未列出From,而包含To, cc, BCC等。因此从语法角度来看这是错误的。删除.From

后,它对我有用
  

您可以从下面的列表中看到

Methods
Properties
Actions
AlternateRecipientAllowed
Application
Attachments
AutoForwarded
AutoResolvedWinner
BCC
BillingInformation
Body
BodyFormat
Categories
CC
Class
Companies
Conflicts
ConversationID
ConversationIndex
ConversationTopic
CreationTime
DeferredDeliveryTime
DeleteAfterSubmit
DownloadState
EntryID
ExpiryTime
FlagRequest
FormDescription
GetInspector
HTMLBody
Importance
InternetCodepage
IsConflict
IsMarkedAsTask
ItemProperties
LastModificationTime
MarkForDownload
MessageClass
Mileage
NoAging
OriginatorDeliveryReportRequested
OutlookInternalVersion
OutlookVersion
Parent
Permission
PermissionService
PermissionTemplateGuid
PropertyAccessor
ReadReceiptRequested
ReceivedByEntryID
ReceivedByName
ReceivedOnBehalfOfEntryID
ReceivedOnBehalfOfName
ReceivedTime
RecipientReassignmentProhibited
Recipients
ReminderOverrideDefault
ReminderPlaySound
ReminderSet
ReminderSoundFile
ReminderTime
RemoteStatus
ReplyRecipientNames
ReplyRecipients
RetentionExpirationDate
RetentionPolicyName
RTFBody
Saved
SaveSentMessageFolder
Sender
SenderEmailAddress
SenderEmailType
SenderName
SendUsingAccount
Sensitivity
Sent
SentOn
SentOnBehalfOfName
Session
Size
Subject
Submitted
TaskCompletedDate
TaskDueDate
TaskStartDate
TaskSubject
To
ToDoTaskOrdinal
UnRead
UserProperties
VotingOptions
VotingResponse
相关问题