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.
I'm just setting up to do some tests on this. My templates only have a very small .png graphic at the top and a tiny .png in the footer so hopefully the file sizes won't increase that much but I'll post back what I find.
EDIT: So I don't see more than about a 20KB difference in file sizes with my documents that have embedded graphics including two that have full size 8.5x11 .jpg files as the backgrounds. When saving either from the .docx to .doc and also back to another .docx
I have an update
I confirm the docx to doc to docx works, but... The size of the files are increased tremendously, basically because of the original images contained in the documents.
That said, in my scenario I approced the problem from another point of view.
My scenario has a cover page, followed by some other pages, based on the selections the user made in the main program (external to word).
The options are read from a file xml, so maybe a final document is like this:
cover + doc1 + doc456 + doc236 + doc55
another document might be:
cover + doc73 + doc12 + doc99
etc... where with the plus sign "+" I mean the file was inserted with our fancy InserFiles command :D
What I did was remove the pictures in all the files and kept the one I really needed. The who generated the documents applied the text over the original document, having header e footer full with images in each document!
But, re-thinking the whole process, I only need images in the footer and header of the cover.
The docs inserted are now just formatted text and images related with the single document.
I hope this might be of any help
Thank goodness - it's not just me (and many of my customers) with the problem. That helps eliminate the one of the answers I get from people telling me its something I'm doing wrong or that my documents are bad.
I thought I had tried the double save option once but I'll give it a try again.
I do have a workaround option where I save the .docx as a .doc then use InsertFile on the .doc file then delete the temp .doc file, but there are differences as well when I do this sometimes as I'll lose things from the footers sometimes. My other workaround is to create a new doc, copy/paste the .doc contents, reapply my Word styles but that introduces an artifact when the docx file are then inserted. Plus you can't minimize the pages when doing the copy/paste for some reason they turn out blank, so the maximized windows being opened/closed obscures the desktop and rolling progress bar screen during the operations. So neither work around so far is great.
And recompiling won't matter. I've recompiled my code hundreds of times over the last few months and on multiple computers.
Hi Ian,
thanks for opening the topic, I'm having the same issue related with the Inserfiles command.
The problem is on my development computer, so, after a long read of this entire thread, I tried this:
apparently, this operation fixes the problem and the insertfiles command now works.
On a side note, I also recompiled the word project (maybe can help?)