In Outlook SecureTemp Files Folder and Red X's in Email Messages I explain what the SecureTemp folder is and issues that result from a "full" SecureTemp folder. I also tell you how to find the folder and empty it manually.
While you can delete the contents of the SecureTempFolder manually, you may want to delete the folder each time you close Outlook.
If you prefer to run this manually whenever you feel like it, change Private Sub Application_Quit() to Public Sub EmptySecureTemp() and run it as needed.
To use, open the VBA editor using Alt+F11 then add the code to ThisOutlookSession.
Reprinted with permission of Peter Marchert
Option Explicit Private Sub Application_Quit() '===================================================================== ' Deletes the files of the SecureTempFolder (OLK) when closing Outlook ' (c) Peter Marchert - //www.outlook-stuff.com ' 2008-11-06 Version 1.0.0 '===================================================================== Dim objFSO As Object Dim objWsh As Object Dim objFolder As Object Dim strRegKey As String Dim strOLK As String On Error Resume Next '--------------------------------------------------------------------- ' To read data from the registry '--------------------------------------------------------------------- Set objWsh = CreateObject("WScript.Shell") '--------------------------------------------------------------------- ' Set the registry key to read '--------------------------------------------------------------------- strRegKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\%.0\Outlook\Security\OutlookSecureTempFolder" '--------------------------------------------------------------------- ' Read SecureTempFolder from the registry '--------------------------------------------------------------------- Select Case Left(Outlook.Version, 2) Case "9.": strOLK = objWsh.RegRead(Replace(strRegKey, "%", "9")) Case "10": strOLK = objWsh.RegRead(Replace(strRegKey, "%", "10")) Case "11": strOLK = objWsh.RegRead(Replace(strRegKey, "%", "11")) Case "12": strOLK = objWsh.RegRead(Replace(strRegKey, "%", "12")) Case "14": strOLK = objWsh.RegRead(Replace(strRegKey, "%", "14")) Case Else MsgBox "Cannot determine your Outlook version.", vbCritical + _ vbOKOnly, "Delete OLK" Exit Sub End Select '--------------------------------------------------------------------- ' VBA does not provide comfortable functions to delete files, so we use ' VB-Script. '--------------------------------------------------------------------- Set objFSO = CreateObject("Scripting.FileSystemObject") '--------------------------------------------------------------------- ' Delete all files in the SecureTempFolder (True = force deleting) '--------------------------------------------------------------------- Call objFSO.DeleteFile(strOLK & "*.*", True) '--------------------------------------------------------------------- ' Reference the SecureTempFolder '--------------------------------------------------------------------- Set objFolder = objFSO.GetFolder(strOLK) '--------------------------------------------------------------------- ' Open the folder if it is not empty '--------------------------------------------------------------------- If objFolder.Files.Count Then Call Shell("explorer.exe " & strOLK) '--------------------------------------------------------------------- ' Clean Up '--------------------------------------------------------------------- Set objFolder = Nothing Set objFSO = Nothing Set objWsh = Nothing End Sub
Hi Diane
It was so helpful to find this code. I've used Outlook 2010 since it appeared and scratched around under the surface to fix a host of issues usually with your help...
... and then in December 2023 I found the cache... with files in it.
So after some searching for a solution I arrived here, and I thought "Ah, it's Diane again, doing what she does". The code worked and the temporary files have buzzed off :-)
A point to note was that on quitting Outlook, breakpoints display VBA briefly and then the code continues. I tried commenting out "on error..." but with no change. I was able to run the code in debug mode by purposefully running the subroutine, but not on quitting the program.
Kind Regards
Stephen Ford, UK