?
Solved

Outlook vba cannot save a large Msg file to disk. error -2147024882 There is not enough free memory

Posted on 2014-10-13
18
Medium Priority
?
762 Views
Last Modified: 2014-10-15
I'll bet there is no easy solution to this problem, but I thought I would try anyhow.

I cannot do a Saveas of a particular email message.

 The email's total size is only 6 MB, but the email has an odd structure which contains 3 levels:

Level 1 is the email with subject "look at this"

Level 2 is an attachment named "Master.msg". it  contains 100 sub attachments named  "Att1.msg to "Att100.msg"

level 3 are the attachments.  It is possible that some of them have Level 4 sub attachments, but I don't think so.

The failing code is very simple:
Sub test()
   Dim Item As Outlook.mailItem
   Set Item = ActiveExplorer.Selection(1)
   On Error Resume Next
   Item.SaveAs "c:\aaatmp\test451.uni", olMsg
   Debug.Print InputBox("", , Err & " " & Error)

   End Sub

Open in new window



The error message is
"-2147024882 There is not enough free memory to run this program. Quit one or more programs, and then try again.

This SaveAs fails in both Outlook 2003 and Outlook 2010.
rberke
0
Comment
Question by:rberke
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
  • 4
18 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 40379470
Hi, rberke.

Can you save the item manually?
0
 
LVL 5

Author Comment

by:rberke
ID: 40379541
Yes I can save it manually, and I already used that technique to manually workaround the problem caused by this particular email.

This is not a high priority. Myprogram has been running for over two years and this is the first time the .SaveAs failed.

Nonetheless, I posted this question in hopes of a long term solution because the error might happen on future emails. I already implemented a workaround which slaps a big MSGBOX  onto my screen saying "Bob  fix the problem manually!".

But, that workaround is ugly, so I had hoped someone might have an alternative way of saving the message. I might try using Redemption when I get some spare time, but I prefer to not use that tool.
0
 
LVL 46

Expert Comment

by:aikimark
ID: 40379559
Are you trying to save the individual attachments or the entire (selected) item?
0
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
LVL 76

Expert Comment

by:David Lee
ID: 40379574
How big is the message?
0
 
LVL 46

Expert Comment

by:aikimark
ID: 40379583
@BlueDevilFan

Would there be a size other than the 6MB already stated?
Or are you referring to the body text size?
0
 
LVL 76

Expert Comment

by:David Lee
ID: 40379671
@aikimark

Doh!  No, I missed that he'd given the message size in his original post.  Thanks for pointing that out.

@rberke

I'm not aware of any size limit on saving messages via VBA.  Just to make though I just ran your code on a 6mb message I have and it saved without a problem.  Do you have another message of similar size?  If so, can you save it via the macro?
0
 
LVL 46

Accepted Solution

by:
aikimark earned 2000 total points
ID: 40379757
@BlueDevilFan

I have a hypothesis but no way to test it.  Since he has attachments that contain attachments, the .SaveAs method might be doing some (internal) recursive calls and running out of stack space.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 40380199
@aikimark

I don't know of any way to test that theory either.  I found this conversation on a Microsoft forum where a person ran into the same problem.  Pay attention to the responses from Dmitry Streblechenko, the creator of Outlook Redemption and Outlook Spy,
0
 
LVL 46

Expert Comment

by:aikimark
ID: 40380218
Dmitry recommended trying a unicode format save: olmsgunicode
0
 
LVL 46

Expert Comment

by:aikimark
ID: 40380280
One other possible reason might be the number of application objects that are started to handle the diverse attachment file types.  Not sure there is a solution, other than the add-in suggested by Dmitry.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 40380462
I'm not convinced that it's an inherent flaw in Outlook.  Dmitry notes that he tested by saving a message with 312 attachments and didn't encounter the same issue.  He also notes that if you can save the message from the GUI, then you ought to be able to save it via VBA.  I'd be interested in seeing if the message will save on other systems or not.
0
 
LVL 46

Expert Comment

by:aikimark
ID: 40380871
What if the Outlook GUI does some specific iteration and does not use the SaveAs method.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 40381370
That's certainly possible.  I'd be surprised though if the developers wrote two different routines to perform the same function.
0
 
LVL 5

Author Comment

by:rberke
ID: 40381761
New informantion:

saveas olmsgUnicode gets the same error
BlueDevilFan asked about sizes.  the answers are posted above.
 
We have now received these 3 emails that have level 3 attachments:
6 MB Email #1 had 100 level 3 attachments and gets erro
r -2147024882 when processed by the the 8 line program in my first post.
2 mb Email #2 had 250 level 3 attachments and gets error -2147024882
1 mb Email #3 had 34 level 3 attachments and worked fine.

the platform does not seem to matter. I have tested all 3 messages with Outlook 2010 under Windows 7, and with Outlook 2003 on Windows small business server 2003. the problem is totally repeatable on both platforms.

aikimark said:
<<internal recursion might be running out of stack space>>
<<What if the Outlook GUI does some specific iteration and does not use the SaveAs method.>>

aikimark appears to be right on both counts.

Manual save works.
Redemption works.
Vba saveAs does not work.

aimark also posted a useful link.

Dmitry's thread discussed several problems that were very similar to mine, and eventually reached the conclusion that Redemption worked. and native vba failed.

I also tried workaround #2 that almost worked, but not quite.
1. Save level 2 attachment (which was named 'master2013.msg') to a disk file named OpenAttachmentManually.txt.
2. Delete original .msg atachment
3. Reattach OpenAttachmentManually.txt to level 1 Mailitem.
4. SaveAS MailItem

My hope was that changing the extension from .msg to .xxx would force Outlook to treat the attachment as a large text file.

Unfortunately, Outlook is too smart for me. At step 3, OUtlook examined the content and noticed that the OpenAttachmentManually.txt was really an email.  Outlook therefore imported "OpenAttachmentManually.txt" and changed the name back to 'Master2013.msg'. (I have noticed this kind of behaviour many times in the past, so it did not surprise me.)

So, I seem to be out of luck.  I could switch to Redemption, or I could just live with my first workaround which is to slap a Msgbox onto the screen warning me of the problem.

rberke

P.S. I thought of a workaround #3 but it is too hard and ugly to implement.

1. Save level 2 attachment (which was named 'master2013.msg') to \\server\share\broken attachments\Master2013.msg
2. Delete original .msg atachment
3. Create file named "seeAttachments.html" which contained hyperlinks to the \\server\share file.
3. Reattach seeAttachments.html to level 1 mailitem.



In case anybody is interested, here is my workaround #2 that failed
Sub test128()
   Dim Item As Outlook.mailItem
   Set Item = ActiveExplorer.Selection(1)
   Dim varAtt, filename
   filename = "c:\aaatmp\OpenAttachmentManually.xxx"
   For Each varAtt In Item.Attachments
        On Error Resume Next
        Kill filename
        On Error GoTo 0
        varAtt.SaveAsFile filename         ' <====this works !!!============== save attachment to temporary folder
        varAtt.delete
        Item.Attachments.Add (filename)    ' <====this almost works, but attachment name reverts to Master2013.msg    Next
    Item.SaveAs "c:\aaatmp\final.msg"
   End Sub

Open in new window

0
 
LVL 46

Expert Comment

by:aikimark
ID: 40381895
you might try file extensions other than txt
0
 
LVL 5

Author Comment

by:rberke
ID: 40382027
both .txt, .html, .xxx and .bin  fail.  I don't think any others are likely to work. I also added an it.save at the bottom of the attach/reattach loop, but that did not help.
0
 
LVL 46

Expert Comment

by:aikimark
ID: 40382071
if .bin fails, then we can abandon that work-around possibility.
0
 
LVL 5

Author Closing Comment

by:rberke
ID: 40383514
I give up.  Points go to aikimark for having good insight into a difficult problem.
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question