A family of Microsoft word processing software products for creating web, email, and print documents.
Great news. The 2302 patch just came out, tested it on a couple computers here and the InsertFile function is now working properly.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
We have a product that assembles custom templates that has been around for about 20 years that operates on a library of about 1 million Word .docx format templates. With users across the world. Its been in use on every version of Word since 2003 (currently only supported on all versions of Office 365 but it also still works on Word 2010). We use the Word VBA function InsertFile to append pages together to create custom documents from the template library.
Recently all of our installations started failing with the InsertFile function returning error 5097 - "Word has encountered a problem". And customers have started reporting the same error.
We traced it down to being introduced in the Aug 3 Build of Word and verified it on multiple computers (both Windows 10 and Windows 11). If we roll back our Word builds through the last 7 builds we found that in every case the June 14, June 29, July 6, July 18 builds of Word work fine. But all 3 builds after that which are Aug 3, Aug 9 and the current Aug 31 fail.
Something appears to have been recently broken by Microsoft in the Aug 3 Build that causes the Word's InsertFile function to fail. This happens on almost all of our Word .docx template we have tested. But when inserting the file via the Word toolbar's Insert > Text From File > browse to the file it works. But it always fails now when calling the InsertFile function via VBA. Again, this is not a new macro or templates. This code has been in use for almost 2 decades and the templates have been in use for for many years. Its only since the recent builds of Word in the last month that installations are now starting to fail everywhere.
This zip file linked below contains the macro vba test function and some example files to reproduce the problem.
When we save those templates that are failing to insert as legacy Word 2003-2007 .doc files they do insert without failing. And if we save them in Word 2003-2007 XML or as an OpenDocument .odt file they insert correctly. But if we save them as Word XML .xml or Strict Word XML .xml they also fail. So there is nothing corrupt in the files, it appears to be inserting current format files of various file formats are failing, but saving those failing files as legacy formats they insert correctly.
How do we submit this problem to Microsoft's Office 365 team as a bug report? This is a serious problem that breaks our product and requires us to have everyone roll back their Office 365 to the July 18, 2022 build and we're in the process of having to update our product to provide instructions when the error occurs on how to roll back Office 365.
The code in the test script is also here. But it needs the .docx files from the ZIP file to operate on.
Sub InsertTest()
Dim DocRng As Range
Dim FileToInsert As String
Dim SourceFile As String
Dim MsgStr As String
Dim MsgResult As Long
On Error GoTo ErrHandler
SourceFile = "c:\temp\CoverLetter.docx"
FileToInsert = "c:\temp\ExecSummaryA.docx" ' This file fails to insert
' FileToInsert = "c:\temp\ExecSummaryB.doc" ' This file works (this was the ExecSummaryA.docx Saved As a .doc file in Word 2003-2007 format)
' FileToInsert = "c:\temp\AccessoriesA.docx" ' This file fails to insert
' FileToInsert = "c:\temp\AccessoriesB.doc" ' This file works (this was the AccessoriesA.docx Saved As a .doc file in Word 2003-2007 format)
Documents.Open FileName:=SourceFile
ActiveWindow.ActivePane.View.Type = wdPrintView
Set DocRng = ActiveDocument.Content
DocRng.Collapse (wdCollapseEnd)
DocRng.InsertFile FileName:=FileToInsert, Range:="", ConfirmConversions:=False, Link:=False, Attachment:=False
Exit Sub
ErrHandler:
MsgStr = "Error: " & Err.Number & " - " & Err.Description
MsgResult = MsgBox(MsgStr, vbSystemModal + vbMsgBoxSetForeground, "Insert Error")
End Sub
A family of Microsoft word processing software products for creating web, email, and print documents.
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Great news. The 2302 patch just came out, tested it on a couple computers here and the InsertFile function is now working properly.
Hi Ian,
If you have a Support Agreement with Microsoft, I would suggest that you attack it form that end as well.
Also, these patch workarounds in the software are only good for some of the people running into the problem. Brand new customers will now get the workaround kick in automatically with instructions to rollback their Office if things like missing footers are a problem.
Only customers in the last 10 months can download a quick patch since we can't put in this patch into older versions of our software.
Everyone else in the field with older editions of our software are faced with having to do a full version upgrade of our software and that's not always possible for companies with very customized systems and customized copies of our templates. And that's just to get the workaround options we put in, that still doesn't work for everyone. So for them they have had to rollback their Office 365 to a July build. And I've had to write up troubleshooting guides on our web site for how to rollback Office for all of them.
Half the companies who have had this problem crop up have had to disable their Office updates and roll it back.
Since these templates have been in use this way for over 20 years (not all 1 million existed at once), they have been built up over the years, and creating with each new release of Word over those years. And about 5-7 years ago the entire library converted to .docx and saved in .docx format. And 100s of thousands of them created since then all in the current .docx formats. And never has anyone in the world on any edition of Word since Word 2003 had these errors occur with any of my templates till this Aug 13 build of Office 365.
So something did change in Word that is balking at the the files. Maybe there is something off in the files, but they were all created by Word so there is no way they can all be corrupted over this history of creating them. Something in Office 365 changed in how the files are read since the InsertFile function has to open and read the file. Maybe its a symptom of something else that changed in Word in that update, but since the files insert fine using the Word toolbar Insert > Text from File it implies something down in the API that is different when being called through VBA vs how they do it using the toolbar when manually inserting files.
The save as legacy .doc format temporarily when the error trapping catches that error does work without causing an error and I can get documents built that way, but it does cause multiple other problems as a longterm solution (i.e. its slower so documents that are built up from large numbers of pages is noticeably slower, and I've noticed some things drop out of the final document like footers. I still need a long term solution.
If I could at least be told by someone at Microsoft exactly why the files won't insert anymore via InsertFile I would have a better idea of how to fix it on my end. Otherwise I'm just poking things seeing what happens and hoping for the best. What if I embark on a months long project to rebuild all 1 million templates by copy/pasting their content into new files is it really solving the problem if the file still insert after that or is it just masking an existing problem that'll still be there that could crop up again.
Hi Ian,
While I appreciate your predicament, for my part, I am convinced that the problem is with the files that are being inserted rather than with the VBA command and I do not believe that there is anything that Microsoft can do about about it.
My suggestion would be to modify your error trapping routine so that it opens the document that was to be inserted, saves it in .doc format and then inserts the .doc format file before deleting it.
The unzip>zip process I used was
which creates a folder containing
Then rezip
and then rename the file and change the file extension