Close document

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In code

Sub macros(fileNameMSG, fileNameRTF)
Dim myolApp As Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myMailItem As Outlook.MailItem

Set myolApp = Outlook.Application
Set myNamespace = myolApp.GetNamespace("MAPI")
Set myMailItem = myNamespace.OpenSharedItem(fileNameMSG)
myMailItem.SaveAs fileNameRTF, olRTF
myMailItem.Close olDiscard
Set myMailItem = myNamespace.OpenSharedItem(fileNameMSG)
myMailItem.Close olDiscard
End Sub

Before second opening file - it is generated error. When I check file - it
is locked. So, what I have to do to unlock file after closing?

Thanks
 
Hello,

set the mailitem to nothing before using it again:

Sub macros(fileNameMSG, fileNameRTF)
Dim myolApp As Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myMailItem As Outlook.MailItem


Set myolApp = Outlook.Application
Set myNamespace = myolApp.GetNamespace("MAPI")
Set myMailItem = myNamespace.OpenSharedItem(fileNameMSG)
myMailItem.SaveAs fileNameRTF, olRTF
myMailItem.Close olDiscard
Set myMailItem = Nothing
Set myMailItem = myNamespace.OpenSharedItem(fileNameMSG)
myMailItem.Close olDiscard
End Sub

Peter
 
I'm having the exact same problem, and for now have had to resort to using
CreateItemFromTemplate instead, which is not ideal because users think they
can change an archived message.

Here's my code:
Dim oTmp As Outlook.MailItem
TmpViewFile = TmpPath & "Email4724.msg"
Set oTmp = gnspNameSpace.OpenSharedItem(TmpViewFile)
oTmp.Display
Set oTmp = Nothing
fs.DeleteFile TmpViewFile, True '<- Gives "Permission denied" error

Interestingly If I open Outlook and go to Windows Explorer and double click
on the Email4724.msg file it comes up ok for display the first time BUT if I
close it and double click again I get an error to the tune that the file is
locked in another app.

Indeed according to the Handle utility it is still locked by Outlook:

C:\Downloads\Microsoft\Handle>handle Email4724.msg

Handle v3.40
Copyright (C) 1997-2008 Mark Russinovich
Sysinternals - www.sysinternals.com

OUTLOOK.EXE pid: 10388 1F28: C:\Documents and Settings\Clive\Local
Setti
ngs\Temp\PropertyManager\Email4724.msg

So this seems like an issue with Oulook - unless I'm missing something?

TIA

Clive (London UK)
 
Outlook caches items when they're opened and releases them from the cache a
period of time after the items are closed. That may be what you are seeing.
And there's no way to tell when an item has been unloaded from the cache
except with the Outlook 2007 object model where you can handle the
item.Unload() event, which fires after item.Close() and before the item is
unloaded from the Outlook cache.
 
Back
Top