public TestReport(string workOrderNumber, string testCondition, string partNumber, string dateCode, string testPerformedOn) { WorkOrderNumber = workOrderNumber; TestCondition = testCondition; TestConditionAbr = testCondition == "As Received" ? "AR" : "TS"; PartNumber = partNumber; DateCode = dateCode; TestPerformedOn = testPerformedOn; try { WordApp = new Word.Application(); //WordApp.Visible = true; //var test = Word.Documents WordDoc = WordApp.Documents.Open(@"test_report_location\report_template.docx", true, true); WordDoc.Activate(); // make a copy of the report template before entering in any data to use in case number of data rows exceeds limit for one page WordApp.ActiveDocument.Bookmarks[@"\Page"].Range.Copy(); // create correct page break type to add when needed //object breakType = Word.WdBreakType.wdPageBreak; } catch (Exception err) { sw = new StreamWriter(ErrorLogFilePath, true); sw.WriteLine($"{DateTime.Now.ToShortTimeString()}\nReport constructor -- {err.Source}; {err.TargetSite}\n{err.Message}\n"); sw.Close(); if (WordDoc != null) { WordDoc.Close(Word.WdSaveOptions.wdDoNotSaveChanges, Word.WdOriginalFormat.wdOriginalDocumentFormat, false); } if (WordApp != null) { WordApp.Quit(); } throw; } }