We have a Microsoft Word template that contains macros, which was working fine but all of a sudden in the last few days, whenever you invoke the template you get the following error:

Word has encountered a problem.
If you open the template file instead of invoking a New document from it, you get a more detailed error:

Object library invalid or contains references to object definitions that could not be found
This was obviously due to a change in our systems. After googling awhile, I found this article which explains that the error can happen after installing a certain Windows update: http://support.microsoft.com/default.aspx?scid=kb;en-us;932349. The update installs new versions of certain Visual Basic 6.0 Runtime files. The article provides a link to a cumulative update rollup which I tried, to no avail.
Upon further investigation, I found that the files had been updated fine. However, there is a corresponding EXD file that is created for each of the runtime files, when you use the controls provided by the runtime files in the Visual Basic designer. When the runtime files are updated, these EXD files are now invalid and hence this error occurs. To fix the error, you need to delete the EXD files and they will be re-created as needed.
These files should be located in the folder: %APPDATA%\Microsoft\Forms\
On Windows XP, it is usually located in:
C:\Documents and Settings\%USERNAME%\Application Data\Microsoft\Forms\
And on Windows Vista/7:
C:\Users\%USERNAME%\AppData\Roaming\Microsoft\Forms\

It was easy enough to fix for myself, but others were having this problem – so I made a script that given the username deletes the files. I had users run the script (you can post it as a link on a webpage and as long as you use Internet Explorer and low security settings it can be invoked from there):
// Function to delete EXD files from user Application Data folder
// This is to resolve an issue with Word VBA macros that use VB runtimes, which the EXDs point to
function deleteEXDs(){
var strToPath = "%appdata%\\Microsoft\\Forms\\";
try {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var shell = new ActiveXObject("WScript.Shell");
}
catch (err) {
alert("Could not create ActiveXObject.\nThis script should be run from Internet Explorer, \n" +
"with low security settings (e.g. Intranet or Trusted Sites).");
return;
}
try {
var appdata = shell.SpecialFolders("AppData");
var strToPath = appdata + "\\Microsoft\\Forms\\";
var fldr = fso.GetFolder(strToPath);
var noEXDs = true;
for (var e = new Enumerator(fldr.Files); !e.atEnd(); e.moveNext())
{
if (fso.GetExtensionName(e.item()).toLowerCase() == 'exd')
{
noEXDs = false;
try {
var filename = new String(e.item());
e.item().Delete();
alert('DELETED ' + filename);
}
catch (err)
{
alert("Error - could not delete " + e.item() + ".\nDescription: " + err.description);
}
}
}
if (noEXDs) alert('No EXD files found.');
}
catch (err) {
alert("Error - could not clean up EXD files.\nDescription: " + err.description);
}
}
Edit 26 Oct 2010:
Thanks for all the positive comments!
I noticed that this solution of deleting the EXD files is now also being mentioned in the Microsoft KB article: http://support.microsoft.com/kb/957924/en-us
Edit 1 July 2011:
Thanks to the comment below by Paul M Edwards, I updated the script to use the AppData environment variable, so it should now work with Windows newer than XP.
96 Comments
OMG, you did it!! We were convinced we were going to have to go back to an older version of Excel. You saved the day. Thanks!
Ohhhh man ,,, thank you soooo much ,,, it works perfectly
You are just Great.. thank you man.
Thnx buddy,
it work for me in VBA.
You are simply awesome. Thanks a lot.
Got my Word based program back up and running again….thanks!
Thanks a Lot !!!
Perfect! Thanks a lot. You saved the day.
Great! Worked for me as well! I had Office 2003 and I upgraded “only” Outlook to 2010. After that I started getting the above error at start-up for Excel. After I read your article, I deleted the MSComctlLib.exd which was the only file in that path and then restarted my Excel. The error vanished and I also saw that there was a new file created by same name “MSComctlLib.exd”.
Thank You So Much!!
OMG! Thank God i found your thread, same warning was also fixed! Thank you!
This is a great tip which has been very helpful.
One addition I would like to make is that the following path will provide the correct folder location regardless of Windows version or username by using an environmental variable:
%APPDATA%\Microsoft\Forms
Instead of “USER” in the paths, you can use %USERNAME%, i.e.:
On Windows XP, it is usually located in:
C:\Documents and Settings\%USERNAME%\Application Data\Microsoft\Forms\
And on Windows Vista/7:
C:\Users\%USERNAME%\AppData\Roaming\Microsoft\Forms\
Thanks Paul, I updated the post.
You are a genius! I hit this minefield when upgrading to Eggshell 2010 and my addin in 2003/2007 fell over spectacularly. Thank you 10^6.
Trevor
Thanks a bunch mate
Worked like a charm in Win 7 – thanks very much.
Thanks so much for this. This “works a treat” as they say across the pond. How do I invoke the script? What do I need to save it as?
Excellent, thanks a bunch !!
You can save the script as a javascript file (e.g. script.js). If you then double-click on it it should work.
You can also link to it from a web page, and if you are running Internet Explorer with low security settings when you click on the link the script will have access to the local filesystem and do what it needs to do. Of course, the low security settings should only be used in a protected environment otherwise it will expose you to dangerous scripts on the internet. So you would add only the webpage you have hosted it on (preferably on your intranet) to the Trusted Sites group, or something like that.
Hello;
Greate your solution is working fine … Thanks very much genius!
Dear Lessan… from now on you’re my new personal hero. Thank you very much!
Thank you very much. I wanted to destroy my computer.
Works a treat, thanks for sharing!
You cannot imagine how much trouble I’ve had with this in the past,thank you sooo much.
I do search engine optimization for Kona, Hilo, and Waimea on the Big Island in Hawaii.
Very Nice. This error appeared to me when I switched from Office 2000 to Office 2010. Now by deleting the EXD I do not have the problem anymore. However hope that deleting this EXD will not affect another thing,
Sheers
Thank you very much!!! You saved my project!
Thanks for this post!
It was really helpfull, and easy to understand.
Hi! I’ve received the same error, but with no previous Excel upgrade. I have been using Excel 2003 on Win XP for a while.
Only see the error when I run a particular XLS that uses lots of macros and DDE to communicate with another application. The rest of the XLSs, even those with macros,work just fine. After I receive the error message, VBA Editor stops at the definition of a sub() function.
Any ideas? I’ve tried already deleting the .EXD files, to no avail. Thanks!
pbertu
Awesome! Thank you ! Thank you! I found this site that exactly gave me the resolution!
Thanks dude!
Thank you so much! You are my hero!
You have saved my sanity!!! A quick deletion of a single EXD file did the trick! Unbelievable…
Works like a charm. Thank you!
WoW you made my day. Worked like a charm
Thank you Thank you
Thanks man, saved my day too. Bloody microsoft should do that when they run the installation routine of a new office version.
Thankyou so much! Finally solved this. I too was looking at going back to an old version of Excel to solve this problem. Found nothing of value in solving this on Microsoft sites (without your references).
It really works fine. This error happened after upgrade from office 2007 to office 2010. After googling in italian I found the solution here, in English. Thank you very much. My head is safe (it was my boss’s pc!)
Nailed it. Thanks!! Was troubling me since last couple of weeks.
Great!!! It really did perfectly
which exd files need to be deleted? I see a bunch of them but i also see some box files. do they need to be deleted too?
Thanks a lot. its really a great work.
YOU ROCK!!!
Thnx…. It worked for me..!
This worked like a CHARM…thank goodness. I installed MS Project 2010 on 01/22/2012 and had tried uninstalling and going back to 2007 and nothing worked. I deleted the *.exd file and now MS Excel works perfectly.
It’s work! Thanks so much!
Thank you for this solution. The moment I deleted these files all my templates worked fine again.
Thank you very much – worked a treat!!!
One Trackback
[...] deleting the mscomct2.exd file as mentioned in this two sites “Microsoft” and “lessanvaezi” but the error stil pops. I checked and the new .exd file was generated.Some Additional [...]