When developing export capabilities for my .NET application to Microsoft Word and Microsoft Excel, I noticed that whenever I created a new document through COM automation, a new instance of either Microsoft Word or Microsoft Excel would be opened, resulting in many instances living in the Windows taskbar. On Windows 7 this wasn’t too noticeable, […]

This article was posted by Independent Software, a website and database application development company based in Maputo, Mozambique. Our website offers regular write-ups on technical and design issues, ranging from details at code level to 3D Studio Max rendering. Read more about Independent Software's philosophy, or get in touch with Independent Software.

When developing export capabilities for my .NET application to Microsoft Word and Microsoft Excel, I noticed that whenever I created a new document through COM automation, a new instance of either Microsoft Word or Microsoft Excel would be opened, resulting in many instances living in the Windows taskbar.

On Windows 7 this wasn’t too noticeable, since instances of Word or Excel would always have their own taskbar icon (or perhaps I had taskbar grouping off), but it was definitely becoming a problem on Windows XP. I set out to find out how I could open the running instance of Microsoft Word or Microsoft Excel rather than create a new one, so I could add a new document or worksheet to it.

This is the required to create a new instance of Microsoft Excel:

To open a Microsoft Word instance through .NET automation, do:

Now, to open the running instance of Excel (if there is one), the code must be changed to:

And for Microsoft Word:

If there is an instance available, a new Microsoft Word document or Microsoft Excel workbook you subsequently create will now be added to the running instance.

Did this article help you out? Please help us find more time to write useful guides & articles like this by donating a buck or two. It'll keep us coffee-fueled. Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *