【发布时间】:2020-10-23 01:17:26
【问题描述】:
如何改变循环?
我真的需要帮助。我有一个宏,可以使用以下代码从消息中下载 PDF:
Sub SaveAttachmentsFromSelectedItemsPDF2()
Dim currentItem As Object
Dim currentAttachment As Attachment
Dim saveToFolder As String
Dim savedFileCountPDF As Long
saveToFolder = "c:\dev\pdf" 'change the path accordingly
savedFileCountPDF = 0
For Each currentItem In Application.ActiveExplorer.Selection
For Each currentAttachment In currentItem.Attachments
If UCase(Right(currentAttachment.DisplayName, 4)) = ".PDF" Then
currentAttachment.SaveAsFile saveToFolder & "\" & _
Left(currentAttachment.DisplayName, Len(currentAttachment.DisplayName) - 4) & "_" & Format(Now, "yyyy-mm-dd_hh-mm-ss") & ".pdf"
savedFileCountPDF = savedFileCountPDF + 1
End If
Next currentAttachment
Next currentItem
MsgBox "Number of PDF files saved: " & savedFileCountPDF, vbInformation
End Sub
我有一个很大的数字,大约 4k。它只让我做一些,然后在标题中给我这个信息。有没有办法更改我的代码以分组或一个一个地处理它们,而不是一次全部处理?
【问题讨论】:
-
也许尝试弄乱this article for that error 中提到的设置?或者,如果可能的话,修改您的脚本以在保存附件后将每条消息移动到存档 pst,因为这可能会将它们从服务器中删除并避免错误?
-
我想我只是想要一种方法来执行每条消息而不是在一个允许它超过 256 条打开消息的大循环中