Share via

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: Most helpful
  1. Anonymous
    2022-09-14T15:00:01+00:00

    The problem is definitely spreading as customers upgrade their Office 365. This weekend a company in Australia encountered the problem when I started reporting it in these threads. Today a company in the UK is getting it. And both of these companies are using our templates that are different than the ones I used in the test cases. Just confirmed that the problem was resolved for the UK company after they rolled back their Office 365 to the July 18 build.

    Was this answer helpful?

    2 people found this answer helpful.
    0 comments No comments
  2. Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
    2022-09-11T20:12:05+00:00

    After changing the path to the folder into which the files were unzipped, running the InsertTest macro here on a Windows 10 machine running a 64-bit installation of Microsoft 365 Apps for enterprise, Version 2208 (Build 15601.20088 Click-to-Run) Current Channel, the CoverLetter.docx document was opened and lhe ExecSummaryA.docx file was inserted.

    On a Windows 11 machine, to get around Microsoft's infernal macro security measures, I had to copy the code from the TestMacro.dotm into a macro enabled template that I created and saved in the Word STARTUP folder.

    Then, after changing the path in the macro to the folder into which the files were unzipped, running the InsertTest macro with a 64-bit installation of Microsoft 365 Apps for enterprise, Version 2207 (Build 15427.20210) the CoverLetter.docx document was opened and lhe ExecSummaryA.docx file was inserted.

    However, I did encounter the error after updating the Windows 11 machine to the same version as on the Windows 10 machine - Version 2208 (Build 15601.20088 Click-to-Run) Current Channel.

    I have reported the issue to the Microsoft Word Product Team and will post back here with their response.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  3. Anonymous
    2022-09-11T21:07:55+00:00

    I have been trying all sorts of variations trying to pinpoint something wrong in the documents. I can't see any way this is something amis or corrupt in the .docx files as it is happening on so many of them here. We literally have a library of 1.1million templates like these and most of the ones we are testing are now failing. I've only included a few for testing purposes here. I have tried taking some of the failing files like these .docx files and saving them as .doc and the .doc versions insert okay, but if I then take that .doc file saved from the original .docx that was failing and save it again as another .docx file then it fails again. We do have some templates that work just fine but one 1 test on 1 computer they failed once. The process of saving it out in an intermediate format then to another new .docx you would think would take care of anything "amis" with the documents. Again, this is a product line of over 1 million templates across 500 products that has been around for many years and only in the last month have installations of our software that call the InsertFile function started failing. And the only change to any of these systems has been the updates to the Word 365. And the only thing that has made them work again is rolling back to a previous build.

    It appears to be something recently broken in Word 365 in the Aug 13 update - or maybe its a side effect of something else - or its a bug that's been there longer that was unmasked by another recent change. We're at the point we can only poke around experimenting with what works and what doesn't without any way to do any internal debugging to know what is really happening. But since these failing files work in some cases and its all happening with current format files (even current format .xml formats), but it always works when we save them out as old legacy .doc or .xml formats they are working it points to something in the InsertFile function balking on something in the file that it probably shouldn't.

    Was this answer helpful?

    0 comments No comments
  4. Jay Freedman 207.7K Reputation points Volunteer Moderator
    2022-09-11T20:45:01+00:00

    In my case, on a Windows 10 machine running a 64-bit installation of Microsoft 365 Apps for enterprise, Version 2208 (Build 15601.20088 Click-to-Run) Current Channel, I do see the error for ExecSummaryA.docx and AccessoriesA.docx. The .doc versions insert correctly.

    However, when I change the FileToInsert string to point to a different .docx file on my drive, it does insert correctly. I tried it with a document containing images, and another containing equation content controls. Copying the quote box from ExecSummaryA.docx and pasting it into my document with the images, again the macro succeeded. These results lead me to suspect that there's something amiss in the .docx template files, perhaps in the XML of those files. I'll have to leave it to the Microsoft product team to investigate.

    Was this answer helpful?

    0 comments No comments