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();
}
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With