Outlook 标题 附件 提醒 VBA 代码

 

网上转载,仅供参考

经常为忘了写标题和贴附件而苦恼,今天开始不用了。。。

老大推荐了这个宏,很好很强大,只是存在几个Bug...
1.
代码格式十分FT..提示用中文
2.
邮件的回复、转发等内容不用检查
3.
提示在前台而不是后台
4.
取消发送不是将邮件保留到草稿箱。

操作如下:
a. 
打开outlook
b. 
“Alt + F11” 键来打开VB Script,或者[工具]->[]->[Visual Basic 编辑器]
c. 
点击左侧树状目录最下面的“ThisOutlookSession”,看到右边出现空白的编辑窗口
d. 
把代码拷贝到编辑窗口,保存,退出VB Script编辑。

代码修改了如下:

重启失效的原因是需要修改outlook工具”-->“”-->“安全性”-->修改安全级别为中或者低 

这样重启outlook的时候,才会提示你是否加载该宏,而不是直接就默认拒掉

 

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

If TypeName(Item) <> "MailItem" Then Exit Sub

Dim intRet As Integer

'CHECK FOR BLANK SUBJECT LINE
If Item.Subject = "" Then
    intRet = MsgBox("
警告:您的郵件缺少主題,請注意填寫" & vbNewLine, vbOKOnly + vbMsgBoxSetForeground + vbExclamation, "缺少主題")
    If intRet = vbOK Then
        Cancel = True
        Exit Sub
    End If
End If

'CHECK FOR FORGETTING ATTACHMENT
Dim intRes As Integer
Dim strMsg As String
Dim strThismsg As String
Dim intOldmsgstart As Integer

' Does not search for "Attach", but for all strings in an array that is defined here
Dim sSearchStrings(2) As String
Dim bFoundSearchstring As Boolean
Dim i As Integer

bFoundSearchstring = False
sSearchStrings(0) = "attach"
sSearchStrings(1) = "enclose"
sSearchStrings(2) = "
附件"

' intOldmsgstart = InStr(Item.Body, "-----Original Message-----")
intOldmsgstart = InStr(Item.Body, "
發件人:")

If intOldmsgstart = 0 Then
    strThismsg = Item.Body + " " + Item.Subject
Else
    strThismsg = Left(Item.Body, intOldmsgstart) + " " + Item.Subject
End If

' The above if/then/else will set strThismsg to be the text of this message only,excluding old/fwd/re msg
' if the original included message is mentioning an attachment, ignore that Also includes the subject line at the end of the strThismsg string

For i = LBound(sSearchStrings) To UBound(sSearchStrings)
    If InStr(LCase(strThismsg), sSearchStrings(i)) > 0 Then
        bFoundSearchstring = True
        Exit For
    End If
Next i


If bFoundSearchstring Then
    If Item.Attachments.Count = 0 Then
        strMsg = "
警告:您的郵件缺少附件,請注意添加" & vbNewLine & "確認是否發送?"
        intRet = MsgBox(strMsg, vbYesNo + vbMsgBoxSetForeground + vbDefaultButton2 + vbExclamation, "
缺少附件")
        If intRet = vbNo Then
            Cancel = True
            Exit Sub
        End If
    End If
End If

End Sub

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 可以使用 VBA 编写代码来自动下载 Outlook 邮件附件。以下是一个示例代码: Sub DownloadAttachments() Dim objOL As Outlook.Application Dim objNS As Outlook.NameSpace Dim objFolder As Outlook.MAPIFolder Dim objItem As Object Dim objAttachment As Outlook.Attachment Dim strFolderPath As String Dim strFileName As String ' Set the folder path where you want to save the attachments strFolderPath = "C:\Attachments\" ' Create the Outlook application object Set objOL = CreateObject("Outlook.Application") ' Get the MAPI namespace Set objNS = objOL.GetNamespace("MAPI") ' Get the Inbox folder Set objFolder = objNS.GetDefaultFolder(olFolderInbox) ' Loop through each item in the Inbox folder For Each objItem In objFolder.Items ' Check if the item is a mail item If TypeOf objItem Is MailItem Then ' Loop through each attachment in the mail item For Each objAttachment In objItem.Attachments ' Save the attachment to the specified folder strFileName = strFolderPath & objAttachment.FileName objAttachment.SaveAsFile strFileName Next objAttachment End If Next objItem ' Clean up Set objAttachment = Nothing Set objItem = Nothing Set objFolder = Nothing Set objNS = Nothing Set objOL = Nothing MsgBox "Attachments downloaded successfully!", vbInformation End Sub 请注意,此代码仅适用于 Outlook 客户端,而不适用于 Outlook Web App。 ### 回答2: VBA是Visual Basic for Applications的缩写,是一种用于编写的编程语言,可扩展Microsoft Office应用程序的功能。下面是如何使用VBA自动下载Outlook邮件附件的步骤: 1. 打开Outlook应用程序,并进入“开发者”选项卡。如果未看到“开发者”选项卡,请在“文件”选项卡上选择“选项”,然后在“自定义功能区”中启用“开发者”选项卡。 2. 单击“Visual Basic”按钮,打开Visual Basic编辑器。 3. 在Visual Basic编辑器中,创建一个新的模块。右键点击项目名字,选择“插入”,再选择“模块”。 4. 在新模块中,编写以下代码来自动下载Outlook邮件附件: ```VBA Sub DownloadAttachments() Dim outlookApp As Outlook.Application Dim outlookNamespace As Namespace Dim outlookFolder As MAPIFolder Dim outlookItem As MailItem Dim outlookAttachment As Attachment Dim saveFolder As String ' 设置附件保存路径 saveFolder = "C:\Attachments\" ' 初始化Outlook应用程序和名称空间 Set outlookApp = New Outlook.Application Set outlookNamespace = outlookApp.GetNamespace("MAPI") ' 设置欲遍历的文件夹(可以是收件箱、发件箱等) Set outlookFolder = outlookNamespace.GetDefaultFolder(olFolderInbox) ' 遍历文件夹中每个邮件 For Each outlookItem In outlookFolder.Items ' 检查邮件是否有附件 If outlookItem.Attachments.Count > 0 Then ' 遍历每个附件 For Each outlookAttachment In outlookItem.Attachments ' 保存附件到指定路径 outlookAttachment.SaveAsFile saveFolder & outlookAttachment.DisplayName Next outlookAttachment End If Next outlookItem ' 释放对象 Set outlookApp = Nothing Set outlookNamespace = Nothing Set outlookFolder = Nothing Set outlookItem = Nothing Set outlookAttachment = Nothing End Sub ``` 5. 在代码中,将`saveFolder`变量的值替换为你想要保存附件的文件夹路径。 6. 单击运行按钮或按下`F5`键来运行代码。 7. 运行完代码后,Outlook邮件中的附件将会自动下载到指定的文件夹路径下。 以上就是使用VBA自动下载Outlook邮件附件的步骤和相关代码。请注意,该代码将会下载指定文件夹中所有邮件的附件,如果只需要下载特定邮件或特定文件夹中的附件,需要进行进一步的代码修改。 ### 回答3: VBA是Visual Basic for Applications的简称,是一种用于自动化办公任务的编程语言。要实现VBA自动下载Outlook邮件附件,可以按照以下步骤进行操作: 1. 打开Outlook应用程序并进入“开发人员”选项卡。如果未显示该选项卡,可以打开Outlook设置,并启用开发人员模式。 2. 在“开发人员”选项卡中,点击“Visual Basic”按钮,打开VBA编辑器。 3. 在VBA编辑器中,选择“工具”菜单,然后选择“引用”。 4. 在“引用”对话框中,勾选“Microsoft Outlook Object Library”选项,并点击“确定”按钮。 5. 在VBA编辑器的模块窗口中,插入一个新的模块。 6. 在新的模块中,编写VBA代码来下载Outlook邮件附件。以下是一个基本的示例代码: ``` Sub DownloadAttachments() Dim OutlookApp As Outlook.Application Dim OutlookNamespace As Namespace Dim Inbox As MAPIFolder Dim Item As Object Dim Attachment As Attachment Dim SaveFolderPath As String ' 设置保存附件的文件夹路径 SaveFolderPath = "C:\Attachments" ' 创建Outlook应用程序并登录邮箱账号 Set OutlookApp = New Outlook.Application Set OutlookNamespace = OutlookApp.GetNamespace("MAPI") Set Inbox = OutlookNamespace.GetDefaultFolder(olFolderInbox) ' 遍历收件箱中的所有邮件 For Each Item In Inbox.Items ' 判断是否有附件 If Item.Attachments.Count > 0 Then ' 遍历邮件中的所有附件 For Each Attachment In Item.Attachments ' 保存每个附件到指定的文件夹 Attachment.SaveAsFile SaveFolderPath & "\" & Attachment.Filename Next Attachment End If Next Item ' 释放内存 Set Inbox = Nothing Set OutlookNamespace = Nothing Set OutlookApp = Nothing MsgBox "附件已成功下载到指定文件夹。" End Sub ``` 7. 在代码中,可以根据实际需要修改保存附件的文件夹路径。 8. 运行该VBA代码,即可自动下载Outlook邮件中的附件到指定的文件夹中。 以上是一个简单的示例代码,你可以根据实际需求进行修改和扩展。希望对你有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值