处理大型VBA集合数据 - 过程错误太大

时间:2018-05-16 09:25:01

标签: vba collections

我得到的程序太大,编译错误。

不确定如何重新构造以下代码。

帮助将不胜感激。谢谢。

Dim SpamList As VBA.Collection
Set SpamList = New VBA.Collection
With SpamList
    .Add "abc@gmail.com"
    .Add "abc@aol.com"

    '...Very large list - about 5000 entries

    .Add "abc@yahoo.com"
End With

Dim z as long
For z = 1 To SpamList.Count
    If current email address is in SpamList Then
        msgbox "Spam mail!"
        Exit For
    End If
Next

Set SpamList = Nothing

1 个答案:

答案 0 :(得分:2)

With SpamList等替换为:

Dim FSO As Object
Dim fsList As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Set fsList = FSO.OpenTextFile("c:\spamlist.txt")
Do Until fsList.AtEndOfStream
    SpamList.Add fsList.readline
Loop
fsList.Close

然后将所有条目移动到文本文件,每行一个条目。