Word VBA function InsertFile is now failing on all builds from 15427.20194 Aug 3, 2022 and later

Anonymous
2022-09-11T17:03:40+00:00

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.

InsertFile Failure Test

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

Microsoft 365 and Office | Word | For home | Windows

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.

0 comments No comments
Answer accepted by question author
Anonymous
2023-03-01T15:20:19+00:00

Great news. The 2302 patch just came out, tested it on a couple computers here and the InsertFile function is now working properly.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

66 additional answers

Sort by: Oldest
  1. Doug Robbins - MVP - Office Apps and Services 323.6K Reputation points MVP Volunteer Moderator
    2022-12-06T23:53:44+00:00

    Hi Ian,

    I have received the following response from the Word Project Team

    Quote

    This issue still has an open bug and is being investigated by the crew. We have been following up for updates, but the owning crew has a large workload, and this has been on the backlog. As soon as I have more information, I will let you know.

    Unquote

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2022-12-07T00:23:14+00:00

    That in itself is a great response to hear. Many thanks.

    Was this answer helpful?

    0 comments No comments
  3. Doug Robbins - MVP - Office Apps and Services 323.6K Reputation points MVP Volunteer Moderator
    2022-12-07T01:28:36+00:00

    Hi Ian,

    It does seems to depend upon the WIndows Version

    The error occurs with 64 bit

    Edition Windows 11 Pro

    Version 21H2

    Installed on ‎4/11/2021

    OS build 22000.1219

    Experience Windows Feature Experience Pack 1000.22000.1219.0

    and 32 bit

    Edition Windows 10 Pro

    Version 21H1

    Installed on ‎3/11/2020

    OS build 19043.2130

    Experience Windows Feature Experience Pack 120.2212.4180.0

    but not with 64-bit

    Edition Windows 10 Pro

    Version 22H2

    Installed on ‎14/‎05/‎2022

    OS build 19045.2251

    Experience Windows Feature Experience Pack 120.2212.4170.0

    All running Microsoft 365 Apps for enterprise, Version 2211 (Build 15831.20190 Click-to-Run) Current Channel

    It also did not occur with 64-bit

    Edition Windows 10 Pro

    Version 21H2

    Installed on ‎14/‎09/‎2021

    OS build 19044.2251

    Experience Windows Feature Experience Pack 120.2212.4180.0

    running Microsoft Office Professional Plus 2021 Version 2211 (Build 15831.20190 Click-to-Run)

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2023-01-26T09:35:17+00:00

    Hello Ian,

    thanks for this post/thread. We have developed a software in our company that uses the COM Interopt from Word for automation. We also use the InsertFile command to create documents and experience the exact same problem as you wrote. We have defined a custom Bullet style with a custom graphic for the bullet point. And some users report, that this custom graphic appeares now (very big) at the start of every InsertFile command (see picture). We went back to an older release for office from 2022 and the problem disappeard, so it looks like an update from Microsoft Office causes that problem.

    Image

    Was this answer helpful?

    0 comments No comments