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.
On my Windows 11 machine, if I open the ExecutiveSummaryB.doc document and then via File>Info, I convert it to the latest format and save it as ExecutiveSummaryB.docx, and then run the InsertTest Macro, modified so that the file to be inserted is ExecutiveSummaryB.docx, the error does NOT occur.
That suggests that Jay Freedman's suspicion that there's something amiss in the .docx template files may be correct and that whatever that issue is, the file conversion process corrects it.
That was one of the tests I did earlier and I did so with 2 different documents. The Accessories.docx file as well. I run the script to insert the .docx versions and they fail. Then using Words tool bar do a Save As and save them as the .doc versions and then run the scripts and they insert correctly. But then I opened those .doc files and did another Save As and saved them as new names in the .docx format and running the script on those they both failed. I'll run through that test again. But I also did other variations that are not in the test script where I took the failing .docx files and saved them as legacy 2003-2007 XML format .xml files and those work correctly on the insert. And when I do a Save As on the failing .docx files and save them in the current XML format .xml files or in the Strict format .XML files those also fail. So I'm finding for the files that fail saving them in ANY legacy formats they work, and saving them in ANY current formats fails. I would expect resaving any of the files would get around any thing amis in the files. And if something is amis its happening to scores of files, not just a few. And all files were created with Word. I've tried templates that were created originally years ago with older versions of Word and those created just in the last few months.
I'll retry that test again that you just tried that was failing here earlier.
If there is something amis with the files. I still need to know what that is from any developers or anyone who can test the files or determine what is causing Word's InsertFile to return an error on them all of a sudden when it used to always work. The files haven't changed. And if there is something amis that I can test for with a script or something I would need to know what needs to be fixed and how, and I've got 1.1million templates I'd have to potentially check and fix which would be an enormous effort. All of these templates were created the same way by hand creating a .docx file then using Word VBA scripts to insert the graphics and save them out as .docx files. So they are all created and saved by Word.
I've run the Info > Inspect Document and that doesn't show any problems. I've searched for file integrity checking tools online but can't find anything.
Hi Ian,
Try using File>Info>Convert to convert the *.doc document to the latest format and then save it in that (*.docx) format as simply using File>Save As and changing the save format may not do the same thing as the conversion process. One would however expect that it should.
Of course, it is still Sunday in the US, so we cannot expect anything from the Product Team for a while yet.
Hi Doug,
Yep, still fails. I took the failing ExecSummaryA.docx and using Words toolbar Save As ExecSummaryC.doc (2003-2007 format .doc file) and closed the document. Then opened the ExecSummaryC.doc and did a Save As ExecSummaryC2.docx (back to current format Word document).
Then ran the test insert script 3 times.
ExecSummaryA.docx fails, ExecSummaryC.doc works, ExecSummaryC2.docx fails.
I also opened the ExecSummaryC.doc file, then the Info screen and converted the document to the current format before doing the Save As ExecSummaryC3.docx
That file also fails the same as if just doing a Save As without converting it.
But I did notice that I had to close all the files between test runs including the document containing the macro. There were some times when something worked that normally was failing and I thought I was onto something. But I was just closing the CoverLetter.docx after the failed test, changing the code and rerunning the script to import a different file without closing the macro enabled document. Once I started closing everything between tests it went back to consistently failing on every variation of the .docx files.