运行时错误7:通过VBA将电子邮件导入Excel时出现“内存不足”

时间:2018-07-21 11:47:07

标签: excel vba excel-vba email outlook

我写了一个代码,以选择前一天从Outlook发送到Excel的电子邮件。 当我运行代码时,它陷入两者之间并抛出错误“运行时错误7:内存不足”。 我调试了代码,发现vba正在选择117个Outlook邮件(outlookmail.count)。但只能在excel中获取约30封电子邮件,最终显示出上述错误。 这是代码:

Sub GetFromOutlook()
Dim OutlookApp As Outlook.Application
Dim OutlookNamespace As Namespace
Dim Folder As MAPIFolder
Dim OutlookMail As Variant
Dim i As Integer
Dim sFilter As String
Dim newFolder As Object
Set OutlookApp = New Outlook.Application
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set Folder = OutlookNamespace.GetDefaultFolder(olFolderInbox).Folders("RMShelpdesk")
sFilter = "[ReceivedTime]>'" & Format(Date - 1, "DDDDD HH:NN") & "'"
Set newFolder = Folder.Items.Restrict(sFilter)
i = 1

For Each OutlookMail In Folder.Items
    If OutlookMail.ReceivedTime >= Range("From_date").Value Then
        Range("eMail_subject").Offset(i + y, 0).Value = OutlookMail.Subject
        Range("eMail_date").Offset(i + y, 0).Value = OutlookMail.ReceivedTime
        Range("eMail_sender").Offset(i + y, 0).Value = OutlookMail.SenderName
        Range("Sender_email").Offset(i + y, 0).Value = OutlookMail.SenderEmailAddress
        Range("eMail_text").Offset(i + y, 0).Value = OutlookMail.Body
    End If
    i = i + 1

    Next OutlookMail
Set Folder = Nothing
Set OutlookNamespace = Nothing
Set OutlookApp = Nothing

End Sub

我在行上遇到错误:“ Range(” eMail_text“)。Offset(i + y,0).Value = OutlookMail.Body”。

有人可以帮助我克服这个错误,让所有电子邮件每天都转换为excel吗?

预先感谢 迪帕克

0 个答案:

没有答案