Sebastiaan Hoedeman
Sebastiaan Hoedeman

Reputation: 221

C# Get active Word using NetOffice

We have a C# WPF application which has a button which does nothing more than start Word with the default document path as parameter so the user automatically arrives in the right folder when saving the document.

We use NetOffice to start Word and set the default path. However this influences the loading of AddIns. Since the last Office update some users don't have any AddIns loaded when starting Word using the button. To solve this I tried starting Word simply by using Process.Start() (this solves the disappearance of the AddIns) and then getting the active Word instance with NetOffice to set the default document path.

However NetOffice always starts a new Word instance both when using:

var nativeProxy = Marshal.GetActiveObject("Word.Application")
var activeWordApplication = new Word.Application(null, nativeProxy)

Or:

var activeWordApplication = Word.Application.GetActiveInstance(true);

How can I get the Word instance I started with Process.Start()? I looked at the NetOffice examples and questions of others but I just get a new instance every time.

Thanks in advance!

Upvotes: 1

Views: 377

Answers (1)

Jozef Izso
Jozef Izso

Reputation: 1804

You cannot access the Word process created manually. NetOffice uses COM/interop to communicate with Word and this will always create and "automation" instance of Word.

In the Process Explorer you will see such Word process was started with the /automate parameter. This is done automatically by the COM+ architecture and it is by design.

Upvotes: 0

Related Questions