0
这是我在StackExchange的第一个问题永远:-) 我在MS Outlook VBA运行下面的脚本我怎样才能让我的VBA展望脚本更有效
Sub export()
On Error resume Next
Dim Ns As Outlook.NameSpace
Dim eitem
Dim oFile As Object
Dim fso As Object
Set Ns = Application.GetNamespace("MAPI")
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFile = fso.CreateTextFile("C:\Users\chakkalakka\Desktop\mails.txt")
'Code
For Each eitem In Ns.Session.Folders.Item(12).Items
oFile.WriteLine eitem.SenderName & "§" & eitem.SentOnBehalfOfName & "§" & eitem.ReceivedTime
Next
oFile.Close
Set Ns = Nothing
Set fso = Nothing
Set oFile = Nothing
Debug.Print "Completed!"
End Sub
一般的脚本是工作的罚款和输出是正确的。我的问题是:我需要在> 95000项目的文件夹内运行,并且需要很长时间。
所以我的问题是:我能做些什么来提高性能?
在此先感谢您的帮助
实际需要多长时间?请删除“On Error resume Next”部分,看看是否有任何错误导致延迟。如果是这样,请在这里发布错误消息。 –
将'Items'集合分配给一个局部变量。这可避免在For Each循环中重新评估完整的对象链。 –
On Error Resume Next应该只用于存在绕过错误然后关闭On Error GoTo 0的特定目的。请参阅http://stackoverflow.com/questions/31753201/vba-how-long-does- on-error-resume-next-work/31753321#31753321 and http://stackoverflow.com/questions/29390673/error-handling-in-vba-on-error-resume-next/29390944#29390944 – niton