将附件导出到文件夹时排除签名图像 [英] Exclude Signature images when Exporting attachments to a folder

查看:58
本文介绍了将附件导出到文件夹时排除签名图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有将Outlook附件导出到本地文件夹的代码.

I have code to export Outlook attachments to a local folder.

我注意到签名中的小图像也被另存为附件.

I noticed the little images in the signature are also saved as attachments.

我认为排除签名图像可以通过以下方式实现:

I think excluding the signature images could be done with an If then along the lines of:

 For i = lngCount To 1 Step -1
 If objAttachments.Item(i).Size > 6000 Then

我不知道代码的位置,尤其是End If(在Next之后或之前).

I don't know where to place in my code, especially the End If (after or before the Next).

这是我的代码:

Public Sub Renamefileandexcludesignature(Item As Outlook.MailItem)
    Dim Atmt As Outlook.Attachment
    Dim SavePath As String
    Dim FileName As String
    SavePath = "C:\Users\Antoine\Documents"
    FileName = "Antoine" & ".csv"
    For Each Atmt In Item.Attachments
         Atmt.SaveAsFile SavePath & "\" & FileName
    Next
    Set Atmt = Nothing
End Sub

推荐答案

如果您下载的是特定文件类型,则可以检查附件的扩展名(未测试,但应该可以使用):

If you're after downloading a specific file type you could check the extension of the attachment (untested, but should work):

Public Sub Renamefileandexcludesignature(Item As Outlook.MailItem)
    Dim Atmt As Outlook.Attachment
    Dim SavePath As String
    Dim FileName As String

    Dim objFSO As Object
    Dim sExt As String

    SavePath = "C:\Users\Antoine\Documents"
    FileName = "Antoine" & ".csv"

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    For Each Atmt In Item.Attachments
        sExt = objFSO.GetExtensionName(Atmt.FileName)

        Select Case sExt
            Case "jpg", "png"
                'Do nothing
            Case Else
                Atmt.SaveAsFile SavePath & "\" & FileName
        End Select
    Next

    Set Atmt = Nothing
End Sub

但是我对VBA知之甚少,也不知道在哪里放置 在我的代码中,尤其是EndIf(在Next之后或之前)

But I have little to no knowledge in VBA and don't know where to place in my code, especially the EndIf ( after or before the Next)

这些必须按顺序进行-
如果使用IF然后使用FOR,则必须先使用NEXT关闭FOR,然后使用END IF关闭IF.
如果先使用FOR然后使用IF,则必须先使用END IF关闭IF,然后才能使用NEXT关闭FOR.

These have to go in order -
If you use IF and then FOR you have to use NEXT first to close the FOR and then END IF to close the IF.
If you use FOR and then IF you have to use END IF to close the IF before you can use NEXT to close the FOR.

希望如此.

这篇关于将附件导出到文件夹时排除签名图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆