runtime error 7: out of memory

  • I am not able to run this code get run time error 7. the excel just fill in 20 rows and then stops, the connection is through email exchange server basically I am indexing through emails and filing date, subject and body in excel


    Additionally I am not able to figure out how to modify this code , to just copy those email which has specific string in subject or body .


    I shall be forever grateful for the help.

    My code is:

    Option Explicit

    Sub OUTLOOK_email_export()

    Dim O As outlook.Application

    Set O = New outlook.Application

    Dim ONS As outlook.Namespace

    Set ONS = O.GetNamespace("MAPI")

    Dim MYFOL As outlook.Folder

    Set MYFOL = ONS.GetDefaultFolder(olFolderInbox)

    Dim OMAIL As outlook.MailItem

    Set OMAIL = O.CreateItem(olMailItem)

    Dim i As Object

    Dim mi As outlook.MailItem

    Dim R As Long

    R = 2

    For Each OMAIL In MYFOL.Items

    Cells(R, 1).Value = OMAIL.CreationTime

    Cells(R, 2).Value = OMAIL.SenderEmailAddress

    Cells(R, 3).Value = OMAIL.Subject

    Cells(R, 4).Value = OMAIL.Body

    R = R + 1

    next OMAIL

    End Sub

  • Welcome to Ozgrid.


    Please take a few minutes to read the Forum Rules. I have added code tags for you, the Forum Rules explain why and how.


    The error means just what it says, lack of available memory. You may have to shut down other programs while using this.


    I haven't tested this but see if this works for you.


Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!