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.
Doug - do bribes work?
I have no idea who you would have to bribe.
Another issue that complicates the matter is with the latest update - Version 2209 (Build 15629.20156 Click-to-Run) Current Channel of 64-bit Microsoft 365 Apps for enterprise, there is no problem with the InsertFile command where used on a computer running Windows 10, while here, there is a problem when the computer is running Windows 11.
In addition, the docx files insert without issue when using Version 2209 (Build 15629.20156 Click-to-Run) Current Channel of 64-bit Microsoft Office Professional Plus 2021 on a machine running Windows 10
So, the question is: Is it a Word issue or a Windows issue?
I'll double check with the companies having the problem which channel/plan they have and OS version. But it is happening on both Windows 10 and Windows 11. I have multiple Windows 10 and multiple Windows 11 PCs its failing on and one of the last customers I talked with was running Windows 10.
And only to people using the Current Channel builds that I can recall and also I think more than one person on a couple of these threads I've posted said it worked on their Enterprise install of Office but failed on their Current Channel. All my PCs that are failing are running the Current Channel builds.
As far as I know its supposed to be the same version of Word that people get regardless of the plans. And my understanding is that the Enterprise version is just a licensing difference for # of users. And Current Channel vs Monthly Enterprise or Semi-Annual Enterprise is just the frequency of updates.
So if I were to get a support plan what plan would get me access to a real developer who can find an real answer such as seeing what is in the files that is causing InsertFile to fail or running the test that's replicating it in a debugger that will tell them why InsertFiles is failing (and hopefully be able to propose a fix on their end) or in the least tell me why the files are failing. So many plans on the MSFT web site. Just need something like a single issue plan that doesn't get me a support rep in a data center who's just reading from a script.
Hi Doug,
MSFT has done a couple Word builds now and still InsertFile is crashing with that original problem. In the meantime I've been experimenting with using the Copy/Paste option to rebuild templates and while it fixes the problem with InsertFile returning errors. It is introducing a glitch I can't figure out that's never happened with InsertFile before either.
I took a set of the failing templates (and I've done this manually using the toolbar and programmatically using VBA) and same results. I can create a new document, insert my custom set of Word Styles. One of which is updating the Bullet style with a custom graphic for the bullet point. Then open the original template, do a copy/paste into the new doc and save the new doc.
Then I assemble them all using InsertFile and it doesn't crash InsertFile with the 5907 error anymore and the document assembles - but.
Every time InsertFile inserts a new file and I stop it on that line in the debugger as well to ensure its InsertFile. It has inserted the custom bullet point graphic as the 1st character in the page in front of the content from the file. The files its inserting have no leading character. If I highlight the bullet graphic it isn't in the Bullet Word style either. Its set to Normal and it doesn't act like a bullet point (no indenting and doesn't create a new bullet if you create a new paragraph under it). I've been trying all sorts of things like removing the use of the Bullet style and removing the custom graphic from the Bullet style but it still inserts that graphic. Only if I do not have any bullet points in a template and the copy/paste has not changed the Bullet style does it not insert a bullet graphic ahead of the content of the inserted file.
In the attached pic is the original template that is inserted using InsertFile on the left. On the right is the document InsertFile inserted the template into after having added a page break. It does this on every template it inserts. Same code that I've been using to use InsertFile for decades, never in any other case in any edition of Word with any templates we've used or any of our customers have used over this time has InsertFile stuck an extra character into the document. Only cropped up since I've been trying to come up with a solution to rebuild these templates using Copy/Paste.
And this is also only happening with the templates I've rebuilt by starting with a blank New document and copy/pasting the old content into. One of my other workarounds I experimented with that got around the InsertFile failing was to SaveAs the .docx file as a .doc legacy file and then use InsertFile on the legacy format file - and that gets around the InsertFile error and also doesn't introduce this artifact.
I've also reproduced this on a 2nd computer running the current build of Word and with multiple sets of our templates that have different graphic designs and bullets. And it uses the bullet graphic from whatever document is being inserted.
Any idea what could be causing InsertFile to add an extra element like this into the document?
InsertFile seems to be breaking down in multiple ways now. Still having it crash with the 5097 error when calling InsertFile to insert one file into another, but when using Word's toolbar on the same files selecting Insert > Object > Text from File and picking the file to insert it works fine, where InsertFile returns 5097 (nothing new there, just still doing that since the Aug 3 build).
But now I'm seeing a different behavior with InsertFile that works fine via the Word toolbar. I've been rebuilding the templates that fail by creating a new document and copy/pasting the contents into the new doc. Then InsertFile is working when inserting the the rebuilt template - but as noted in the post above it is introducing a bullet graphic right before the inserted contents.
I just tried using Word's Insert > Object > Text from File via the Word tool bar and it inserts the file without introducing the extra bullet graphic. Using InsertFile on the same file always introduces the bullet graphic - but with the rebuilt docs doesn't crash with the 5097 error.
Still can't figure out any clean way to get InsertFile working properly anymore.
This zip file contains the 2 rebuilt templates I'm using InsertFile on. Via VBA the ExecSummary.docx is opened, a page break is inserted at the end, then InsertFile is called to insert the 2nd file. The results are like in the screenshot in the previous comment where a bullet is inserted before the contents of the file. These same 2 files using the Word toolbar work fine without a bullet added.