Delete EXD files to fix “Object library invalid” error

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.

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

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\

EXD files

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.

This entry was posted in Technology and tagged , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

96 Comments

  1. Texas_Bulldog
    Posted 2011/04/21 at 5:35 pm | Permalink

    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!

  2. Mohamed Azhary
    Posted 2011/05/11 at 5:01 pm | Permalink

    Ohhhh man ,,, thank you soooo much ,,, it works perfectly

  3. Kati
    Posted 2011/05/11 at 9:38 pm | Permalink

    You are just Great.. thank you man.

  4. wasim
    Posted 2011/05/29 at 6:49 am | Permalink

    Thnx buddy,
    it work for me in VBA.

  5. Andre Steyn
    Posted 2011/06/05 at 1:31 pm | Permalink

    You are simply awesome. Thanks a lot.

  6. Posted 2011/06/05 at 3:20 pm | Permalink

    Got my Word based program back up and running again….thanks!

  7. Das
    Posted 2011/06/15 at 1:32 am | Permalink

    Thanks a Lot !!!

  8. Siggi
    Posted 2011/06/17 at 5:39 pm | Permalink

    Perfect! Thanks a lot. You saved the day.

  9. Aijaz
    Posted 2011/06/24 at 12:27 pm | Permalink

    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!!

  10. debbie
    Posted 2011/06/30 at 5:58 am | Permalink

    OMG! Thank God i found your thread, same warning was also fixed! Thank you! :D

  11. Posted 2011/06/30 at 11:33 pm | Permalink

    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

  12. Posted 2011/07/01 at 10:09 pm | Permalink

    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\

  13. Posted 2011/07/02 at 6:12 am | Permalink

    Thanks Paul, I updated the post.

  14. Trevor
    Posted 2011/07/11 at 8:24 pm | Permalink

    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

  15. vish
    Posted 2011/07/25 at 5:43 am | Permalink

    Thanks a bunch mate

  16. Crow
    Posted 2011/08/09 at 7:35 pm | Permalink

    Worked like a charm in Win 7 – thanks very much.

  17. Richard
    Posted 2011/08/11 at 3:23 pm | Permalink

    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?

  18. Vinayak
    Posted 2011/08/11 at 4:12 pm | Permalink

    Excellent, thanks a bunch !!

  19. Posted 2011/08/12 at 7:13 am | Permalink

    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.

  20. Djilli
    Posted 2011/08/12 at 12:39 pm | Permalink

    Hello;

    Greate your solution is working fine … Thanks very much genius!

  21. Aldo David
    Posted 2011/08/12 at 6:48 pm | Permalink

    Dear Lessan… from now on you’re my new personal hero. Thank you very much!

  22. LExts
    Posted 2011/08/31 at 11:56 am | Permalink

    Thank you very much. I wanted to destroy my computer.

    :) )))))

  23. Posted 2011/09/07 at 10:23 pm | Permalink

    Works a treat, thanks for sharing!

  24. Ted
    Posted 2011/09/12 at 7:37 am | Permalink

    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.

  25. Jo
    Posted 2011/09/14 at 12:12 pm | Permalink

    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

  26. Marie
    Posted 2011/09/21 at 3:10 pm | Permalink

    Thank you very much!!! You saved my project!

  27. Max
    Posted 2011/09/27 at 5:23 pm | Permalink

    Thanks for this post!
    It was really helpfull, and easy to understand.

  28. Pbertu
    Posted 2011/09/28 at 11:00 pm | Permalink

    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

  29. MBonda
    Posted 2011/10/06 at 12:19 am | Permalink

    Awesome! Thank you ! Thank you! I found this site that exactly gave me the resolution!
    Thanks dude!

  30. Sharon
    Posted 2011/10/11 at 10:00 pm | Permalink

    Thank you so much! You are my hero!

  31. Vince
    Posted 2011/10/13 at 10:17 pm | Permalink

    You have saved my sanity!!! A quick deletion of a single EXD file did the trick! Unbelievable…

  32. Nicholas Wang
    Posted 2011/10/17 at 12:10 pm | Permalink

    Works like a charm. Thank you!

  33. JoeyJacob
    Posted 2011/10/19 at 10:00 pm | Permalink

    WoW you made my day. Worked like a charm
    Thank you Thank you

  34. Heinz
    Posted 2011/10/28 at 7:36 am | Permalink

    Thanks man, saved my day too. Bloody microsoft should do that when they run the installation routine of a new office version.

  35. CC
    Posted 2011/11/17 at 6:11 am | Permalink

    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).

  36. Posted 2011/11/19 at 11:33 am | Permalink

    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!)

  37. Posted 2011/11/28 at 1:36 pm | Permalink

    Nailed it. Thanks!! Was troubling me since last couple of weeks.

  38. Xenix
    Posted 2011/12/18 at 6:05 am | Permalink

    Great!!! It really did perfectly :)

  39. jay holmes
    Posted 2011/12/21 at 8:42 pm | Permalink

    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?

  40. Posted 2012/01/04 at 7:13 am | Permalink

    Thanks a lot. its really a great work.

  41. Mercy Ventura
    Posted 2012/01/14 at 7:50 pm | Permalink

    YOU ROCK!!!

  42. Vivek
    Posted 2012/01/17 at 7:05 am | Permalink

    Thnx…. It worked for me..!

  43. Bryant
    Posted 2012/01/20 at 9:39 am | Permalink

    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.

  44. Mincho Kardjilov
    Posted 2012/01/26 at 3:47 pm | Permalink

    It’s work! Thanks so much! :)

  45. Posted 2012/02/03 at 1:38 am | Permalink

    Thank you for this solution. The moment I deleted these files all my templates worked fine again.

  46. Lost
    Posted 2012/02/03 at 5:10 am | Permalink

    Thank you very much – worked a treat!!!

One Trackback

  1. [...] 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 [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting