·
5 months ago
Can you explain why the last mail (i = 1) is recreated in a new MailItem instead of just .Send?
Thanks.
Thanks.
如果您的草稿文件夾中有多個草稿消息,現在您希望一次發送它們而不是逐個發送。 您如何在Outlook中快速輕鬆地處理這項工作?
一次回复所有選定的電子郵件:
如果你需要回復多封電子郵件,那麼逐一依賴它們會浪費很多時間,但是,用 Kutools for Outlook's 批量回复 功能,你可以盡快解決這個問題。 Kutools for Outlook:擁有超過20 +便利的Excel加載項,可以在60的日子裡免費試用而沒有限制。 立即下載並免費試用!
|
以下VBA代碼可以幫助您一次性從草稿文件夾發送全部或選定的草稿電子郵件,請按照以下步驟操作:
1。 按住 ALT + F11 鍵打開 Microsoft Visual Basic for Applications 窗口。
2。 然後點擊 插入 > 模塊,將以下代碼複製並粘貼到打開的空白模塊中,請參閱截圖:
VBA代碼:在Outlook中一次發送所有草稿電子郵件:
Sub SendAllDraftEmails() Dim xAccount As Account Dim xDraftFld As Folder Dim xItemCount As Integer Dim xDraftsItems As Outlook.Items Dim xPromptStr As String Dim xYesOrNo As Integer Dim i, k As Long Dim xNewMail As MailItem Dim xTmpPath, xFilePath As String On Error Resume Next xItemCount = 0 For Each xAccount In Outlook.Application.Session.Accounts Set xDraftFld = xAccount.DeliveryStore.GetDefaultFolder(olFolderDrafts) xItemCount = xItemCount + xDraftFld.Items.Count Next xAccount Set xDraftFld = Nothing If xItemCount > 0 Then xPromptStr = "Are you sure to send out all the drafts?" xYesOrNo = MsgBox(xPromptStr, vbQuestion + vbYesNo, "Kutools for Outlook") If xYesOrNo = vbYes Then For Each xAccount In Outlook.Application.Session.Accounts Set xDraftFld = xAccount.DeliveryStore.GetDefaultFolder(olFolderDrafts) Set xDraftsItems = xDraftFld.Items For i = xDraftsItems.Count To 1 Step -1 If i = 1 Then Set xNewMail = Outlook.Application.CreateItem(olMailItem) With xNewMail .SendUsingAccount = xDraftsItems.Item(i).SendUsingAccount .To = xDraftsItems.Item(i).To .CC = xDraftsItems.Item(i).CC .BCC = xDraftsItems.Item(i).BCC .Subject = xDraftsItems.Item(i).Subject If xDraftsItems.Item(i).Attachments.Count > 0 Then xTmpPath = "C:\MyTempAttachments" If Dir(xTmpPath, vbDirectory) = "" Then MkDir xTmpPath End If For k = xDraftsItems.Item(i).Attachments.Count To 1 Step -1 xFilePath = xTmpPath & "\" & xDraftsItems.Item(i).Attachments.Item(k).FileName xDraftsItems.Item(i).Attachments.Item(k).SaveAsFile xFilePath xNewMail.Attachments.Add (xFilePath) Kill xFilePath Next k RmDir xTmpPath End If .HTMLBody = xDraftsItems.Item(i).HTMLBody .Send End With xDraftsItems.Item(i).Delete Else xDraftsItems.Item(i).Send End If Next Next xAccount MsgBox "Successfully sent " & xItemCount & " messages", vbInformation, "Kutools for Outlook" End If Else MsgBox "No Drafts!", vbInformation + vbOKOnly, "Kutools for Outlook" End If End Sub
3。 然後保存代碼,然後按 F5 鍵運行此代碼,將彈出一個提示框來提醒您是否發送所有草稿,單擊 是,看截圖:
4。 此時會彈出一個對話框提醒您發送了多少草稿電子郵件,請參閱截圖:
5。 然後點擊 OK 按鈕,中的所有電子郵件 草稿 文件夾將立即發送,請參閱屏幕截圖:
筆記:
1。 上面的代碼將發送您Outlook中所有帳戶的所有草稿電子郵件。
2。 如果您只想從草稿文件夾發送特定電子郵件,請使用以下VBA代碼:
VBA代碼:從草稿箱發送選定的電子郵件:
Sub SendSelectedDraftEmails() Dim xSelection As Selection Dim xPromptStr As String Dim xYesOrNo As Integer Dim i As Long Dim xNewMail As MailItem Dim xTmpPath, xFilePath As String On Error Resume Next If Outlook.Application.Session.GetDefaultFolder(olFolderDrafts).Name <> _ Outlook.Application.ActiveExplorer.CurrentFolder.Name Then MsgBox "The current folder is not a draft folder", vbInformation, "Kutools for Outlook" Exit Sub End If Set xSelection = Outlook.Application.ActiveExplorer.Selection If xSelection.Count > 0 Then xPromptStr = "Are you sure to send out the selected " & xSelection.Count & " draft item(s)?" xYesOrNo = MsgBox(xPromptStr, vbQuestion + vbYesNo, "Kutools for Outlook") If xYesOrNo = vbYes Then For i = xSelection.Count To 1 Step -1 If i = 1 Then Set xNewMail = Outlook.Application.CreateItem(olMailItem) With xNewMail .SendUsingAccount = xSelection.Item(i).SendUsingAccount .To = xSelection.Item(i).To .CC = xSelection.Item(i).CC .BCC = xSelection.Item(i).BCC .Subject = xSelection.Item(i).Subject If xSelection.Item(i).Attachments.Count > 0 Then xTmpPath = "C:\MyTempAttachments" If Dir(xTmpPath, vbDirectory) = "" Then MkDir xTmpPath End If For k = xSelection.Item(i).Attachments.Count To 1 Step -1 xFilePath = xTmpPath & "\" & xSelection.Item(i).Attachments.Item(k).FileName xSelection.Item(i).Attachments.Item(k).SaveAsFile xFilePath xNewMail.Attachments.Add (xFilePath) Kill xFilePath Next k RmDir xTmpPath End If .HTMLBody = xSelection.Item(i).HTMLBody .Send End With xSelection.Item(i).Delete Else xSelection.Item(i).Send End If Next MsgBox "Successfully sent " & xSelection.Count & " messages", vbInformation, "Kutools for Outlook" End If Else MsgBox "No items selected!", vbInformation, "Kutools for Outlook" End If End Sub
相關文章:
如何通過Outlook從Excel發送個性化群發電子郵件到列表?
如何在不知道Outlook的情況下向多個收件人發送電子郵件?