Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I start MS Office Word from .NET without Add-ins?

Tags:

c#

ms-office

I'm using MS Office 2003 PIA to create a MS Word document from c#.

ApplicationClass officeApplication = new ApplicationClass();

Is there any way to specify that I don't want any office add-ins to be loaded using this method?

EDIT:

I know that one can do this via command line so I'm pretty sure there must be a way to do it from code:

"C:\Program Files\Microsoft Office\Office11\Winword.exe" /a  
like image 871
Andrew Jackson Avatar asked Mar 03 '09 20:03

Andrew Jackson


People also ask

How do I open Microsoft Word from command prompt?

Detailed Solution. The correct answer is Winword. We can launch the Microsoft Word application from the Run window by running the command Winword. Note that this command does not work from the command line as the winword.exe location is not added to the PATH environment variable.


2 Answers

This code unload the AddIns

officeApplication.AddIns.Unload(false);

Edited:

When you need to mix the process start and possibility to use the office "application" interface, you need the Marshal.GetActiveObject command.
Example :

        //startup without plugins
        System.Diagnostics.Process.Start(
            @"Winword.exe",
            @"/a");
        //give a time for startup
        Thread.Sleep(2000);
        //attach to office
        Application officeApplication = (Application)Marshal.GetActiveObject("Word.Application");
like image 165
Avram Avatar answered Sep 25 '22 17:09

Avram


Try this

System.Diagnostics.Process.Start(
  @"C:\Program Files\Microsoft Office\Office11\Winword.exe", 
  @"/a");
like image 37
JaredPar Avatar answered Sep 24 '22 17:09

JaredPar