Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make word visible when opening a document through interop?

I want to open a word document through interop and word must be visible in the process.It looks to be fairly straight forward because there is a parameter called "visible in the open function on a word document. But word is in the background. What am I missing?

static void Main(string[] args)
{
    Microsoft.Office.Interop.Word.Application word = null;
    word = new Microsoft.Office.Interop.Word.Application();

    object inputFile = "c:\\test.docx";
    object confirmConversions = false;
    object readOnly = true;
    object visible = true;
    object missing = Type.Missing;

    // Open the document...
    Microsoft.Office.Interop.Word.Document doc = null;
    doc = word.Documents.Open(
        ref inputFile, ref confirmConversions, ref readOnly, ref missing,
        ref missing, ref missing, ref missing, ref missing,
        ref missing, ref missing, ref missing, ref visible,
        ref missing, ref missing, ref missing, ref missing);
    doc.Activate();

    Console.ReadKey();
}
like image 213
Kasper Hansen Avatar asked May 11 '11 12:05

Kasper Hansen


1 Answers

Hmm. Apparantly both the application and the document has to be visible. So the solution is to add the line (before doc.Activate() ):

word.Visible = true;
like image 187
Kasper Hansen Avatar answered Oct 20 '22 01:10

Kasper Hansen