Print View

Error 5151 or 5097 when opening a Word document using Office Automation from a COM object


When opening a template from the Word.Application object using the .Add method from a COM object the following error may be seen:

5151 Word was unable to read this document. It may be corrupt. Try one or more of the following:
* Open and Repair the file.
* Open the file with the Text Recovery converter.

5097 Word has encountered a problem.

Sample code:

Set objWord = New Word.Application 
objWord.DisplayAlerts = wdAlertsNone 
Set objDoc = objWord.Documents.Add("c:\file.doc")


When run from a COM object Word does not have a user profile loaded. This causes issues with Word, specifically the inability to load Normal.dotm. Word can be seen trying to use the SYSTEM profile:

H:MM:SS.SSSSSSS PM WINWORD.EXE 4032 IRP_MJ_CREATE C:\Windows\SysWOW64\config\systemprofile\AppData\Roaming\Microsoft\Templates\Normal.dotm NAME NOT FOUND Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a DOMAIN\User

To resolve errors in Server Side Office Automation with Word ensure the following folder is created:


If a specific Normal.dotm is required, it can be opened in the code:

Set objWord = New Word.Application 
objWord.DisplayAlerts = wdAlertsNone 
Set objDoc = objWord.Documents.Add("c:\normal.dotm")
Set objDoc = objWord.Documents.Add("c:\file.doc")


Considerations for server-side Automation of Office

To Configure Office Applications to Run Under the Interactive User Account

How to configure Office applications to run under a specific user account

How to configure Office applications for automation from a COM+/MTS package

Add Method [Word 2007 Developer Reference]

Impersonation Level Constants

Problem running Windows Service with Excel Object on Windows Server 2008 (64 bit)

Excel 2007 automation on top of a Windows Server 2008 x64


Microsoft Word 2007
Microsoft Windows Server 2008 x64
Microsoft Office 2007
Microsoft Office 2003

Created: 11th June 2009
Updated: 8th July 2009

Print View

© 2005-2024 Jamie Morrison