将附件导出到文件夹时排除签名图像
Exclude Signature images when Exporting attachments to a folder
我有将 Outlook 附件导出到本地文件夹的代码。
我注意到签名中的小图片也被保存为附件。
我认为可以使用 If then 来排除签名图像:
For i = lngCount To 1 Step -1
If objAttachments.Item(i).Size > 6000 Then
我不知道在我的代码中放在哪里,尤其是 End If(在 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
如果您在下载特定文件类型之后,可以检查附件的扩展名(未经测试,但应该可以):
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
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
。
希望这是有道理的。
使用For i = lngCount To 1 Step -1
(向后循环宏)
声明你的变量
Dim objAttachments As Outlook.Attachments
Dim i As Long
Dim lngCount As Long
现在运行你的循环来保存对象项目
If Item.Attachments.Count > 0 Then
For i = lngCount To 1 Step -1
If objAttachments.Item(i).Size > 6000 Then
objAttachments.Item(i).SaveAsFile FileName
End If
Next i
End If
我有将 Outlook 附件导出到本地文件夹的代码。
我注意到签名中的小图片也被保存为附件。
我认为可以使用 If then 来排除签名图像:
For i = lngCount To 1 Step -1
If objAttachments.Item(i).Size > 6000 Then
我不知道在我的代码中放在哪里,尤其是 End If(在 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
如果您在下载特定文件类型之后,可以检查附件的扩展名(未经测试,但应该可以):
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
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
。
希望这是有道理的。
使用For i = lngCount To 1 Step -1
(向后循环宏)
声明你的变量
Dim objAttachments As Outlook.Attachments
Dim i As Long
Dim lngCount As Long
现在运行你的循环来保存对象项目
If Item.Attachments.Count > 0 Then
For i = lngCount To 1 Step -1
If objAttachments.Item(i).Size > 6000 Then
objAttachments.Item(i).SaveAsFile FileName
End If
Next i
End If