mAttachmentSaver:过滤器文件类型+显示随机消息

时间:2019-05-21 09:55:36

标签: vba outlook

我想知道是否有人可以帮助我对mAttachmentSaver代码(Microsoft VBA代码,仅保存所选电子邮件中的附件)进行一些更改。我希望附件保护程序仅保存.pdf,.doc和excel文件。这是为了排除各种电子邮件附件,例如邮件本身中的图像。我正在按照我在互联网上找到的以下代码的思路进行思考:FileFilter:="Excel,.xls;.pdf,".虽然不确定该放在哪里。 另外,我想要这一行:

   If lNum > 0 Then
        MsgBox CStr(lNum) & " attachment(s) was(were) saved successfully.", vbInformation, "Message from Attachment Saver"
    Else

能够显示随机句子,但是我不确定如何执行此操作。例如:

   If lNum > 0 Then
        MsgBox CStr(lNum) & " attachment(s) was(were) saved successfully. Good job! :)", vbInformation, "Message from Attachment Saver"
MsgBox CStr(lNum) & " attachment(s) was(were) saved successfully. Nice work!", vbInformation, "Message from Attachment Saver"
MsgBox CStr(lNum) & " attachment(s) was(were) saved successfully. You got it!", vbInformation, "Message from Attachment Saver"
MsgBox CStr(lNum) & " attachment(s) was(were) saved successfully. Job done! Time for weekend!", vbInformation, "Message from Attachment Saver"
    Else

提前谢谢!链接到代码:https://gallery.technet.microsoft.com/office/Save-attachments-from-5b6bf54b

2 个答案:

答案 0 :(得分:1)

Mohit的答案涵盖了过滤部分。这是随机消息部分。

现在与示例一样,它带有4条消息,但是如果要扩展它,则必须更改Int((4 * Rnd) + 1)。将4更改为更高的值,例如5,然后您将获得5条随机消息。然后还添加一条带有新消息的Case语句。

If lNum > 0 Then
    Dim Message As String
    Message = CStr(lNum) & " attachment(s) was(were) saved successfully."


    Select Case Int((4 * Rnd) + 1)
        Case 1
            Message = Message & " Good job! :)"
        Case 2
            Message = Message & " Nice work!"
        Case 3
            Message = Message & " You got it!"
        Case 4
            Message = Message & " Job done! Time for weekend!"
    End Select
    MsgBox Message, vbInformation, "Message from Attachment Saver"

答案 1 :(得分:0)

我已经看过代码,可以添加一个If条件,以在要保存的可用附件中过滤出所需的格式。

If strAtmtName(1) = "xlsx" Or strAtmtName(1) = "pdf" Or strAtmtName(1) = "doc" Then

Else: GoTo G:

End If

enter image description here

现在,您还需要在下一个当前for循环As中定义Goto标签G。

enter image description here

因此,如果文件扩展名不是保存附件之前所需的文件扩展名,那么我们正在跳过循环。

希望有帮助!

编辑:

修改其他条件,以将计数减少1,如图中所示。

enter image description here