Automating MS Office97/2000/XP with same C# Code
-
Hi, Can any one tell me how I can Automate MS Office 97/2000/XP using the same C# Code. Using VB I could use Late Binding to do this, but I can not figure out how to do it using C#. I wish to have one C# Program which will work on all versions of MS Office. Thanks for your time Peter Tewkesbury Peter Tewkesbury
-
Hi, Can any one tell me how I can Automate MS Office 97/2000/XP using the same C# Code. Using VB I could use Late Binding to do this, but I can not figure out how to do it using C#. I wish to have one C# Program which will work on all versions of MS Office. Thanks for your time Peter Tewkesbury Peter Tewkesbury
Just off the top of my head, so i have no idea how much work this would be... Abstract the functionality you need from office into an interface or abstract class. Then write a class for each version of office. At runtime detect which version of office is installed and use the proper class. You might have to break each class into a separate assembly so it won't try loading office 97 typelib info when you want xp info. My knowledge of how the references get loaded is minimal though, so this may be an extraneous step. Hope this at least gives you some ideas, James Sonork ID: 100.11138 - Hasaki
-
Just off the top of my head, so i have no idea how much work this would be... Abstract the functionality you need from office into an interface or abstract class. Then write a class for each version of office. At runtime detect which version of office is installed and use the proper class. You might have to break each class into a separate assembly so it won't try loading office 97 typelib info when you want xp info. My knowledge of how the references get loaded is minimal though, so this may be an extraneous step. Hope this at least gives you some ideas, James Sonork ID: 100.11138 - Hasaki
Thanks for the info. I now have a working solution thanks to .NET 1. Write the base class in C# in a seperate DLL & namespace 2. Derive a new class in VB from the base class in another DLL - I can use Late Binding features of VB to automate MS Office (All Versions) without writing pages of code. 3. Use this new class in the top level program (C#) All Thanks for .NET Man I love .NET :) :) :) :) :) :) :) Peter Tewkesbury Developer ibsl technologies