Script to clear Outlook’s Forms Cache

clearformscache.vbs buttonWhen you are developing custom forms for Outlook or when you are a user within a company that has its own custom forms, you’ve probably ran into the error “Outlook cannot open this form…” message on some occasions.

In that case, you’re only solutions it to clear the Forms Cache and try again.

Unfortunately, clearing the Forms Cache is quite a longwinded process. Especially when you are a Custom Forms developer, you’ll probably find yourself clearing the Forms Cache on a regular basis and find it quite time consuming.

The script in this article can be used to quickly delete the Forms Cache.


Built in method to clear the Forms Cache

Before showing the scripted way to clear the Forms Cache, below are the instructions to clear the Forms Cache via the built in method:

  • File-> Options-> Advanced-> section: Developers-> button: Custom Forms…-> button: Manage Forms…-> button: Clear Cache

Scripted method to clear the Forms Cache

The download below contains a vbs-file called clearformscache.vbs to quickly clear Outlook’s Forms Cache. The script can be used “as is” and doesn’t require any additional configuration.

This scripted method requests you to close Outlook and once closed, it locates your Forms Cache folder and then deletes it.

Download: clearformscache.zip

VBS Code for reference

The following code is contained within the zip-file referenced in the section above. You can use the code below for review or copy it to create your own vbs-file.

'====================================================================
'Description: VBS script to clear Outlook's Forms Cache.
' author : Robert Sparnaaij
' version: 2.0
' website: https://www.howto-outlook.com/downloads/clearformscache.htm
'====================================================================

'Close Outlook socially
WScript.Echo "Close Outlook and press OK."

'Set WMI Service
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

'Close Outlook forcefully if it is still running
Set colProcessList = objWMIService.ExecQuery _
 ("Select * from Win32_Process Where Name = 'outlook.exe'")
For Each objProcess in colProcessList
  objProcess.Terminate()
Next

'Get OS version
Set colOperatingSystems = objWMIService.ExecQuery _
 ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
  VersionOS = objOperatingSystem.Version
Next

'Get major OS Kernel number
sOSKernelMajor = Left(VersionOS,(InStr(VersionOS,".")-1))

'Set Shell
Set oShell = CreateObject("WScript.Shell")

'Determine Forms Cache path
If sOSKernelMajor > 5 Then
  sFormsCachePath = oShell.ExpandEnvironmentStrings("%LocalAppData%") _
   & "\Microsoft\Forms"
Else
  sFormsCachePath = oShell.ExpandEnvironmentStrings("%UserProfile%") _
   & "\Local Settings\Application Data\Microsoft\Forms"
End If

'Verify whether the Forms Cache exists and delete it
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(sFormsCachePath) Then
  WScript.Echo "The Forms Cache has been found and will be cleared."
  Const DeleteReadOnly = True
  objFSO.DeleteFolder(sFormsCachePath), DeleteReadOnly
  WScript.Echo "The Forms Cache has been cleared successfully. " _
   & VbNewLine & "Start Outlook and check whether the form works now."
Else
 WScript.Echo "Cannot find the Forms Cache. It has been cleared already. " _
  & VbNewLine & "Start Outlook and check whether the form works now."
End If