Search code examples
c#openxml

Start application to open docx in a comment location


Is it possible to use the OpenXml API to open a document file in a specific spot, like, for instance, in specific comment location, with the default application to open .docx files (or other application if specified)? I know you can use either Microsoft.Office.Interop.Word to open a word file or the Process.Start, but I need to open the document in a specific location.


Solution

  • It is not possible. Explanation given in the following MSDN forum thread:

    https://social.msdn.microsoft.com/Forums/office/en-US/5ea089c9-76fc-49fe-ae33-718fab110eac/start-application-to-open-docx-in-a-comment-location?forum=oxmlsdk&prof=required

    As far as I know, you could not open a word application with Open XML SDK, Open XML SDK is used to operate the data which stored in the file. I suggest you use Word automation to open a word file.

    I think you could create a bookmark named as “B1” in the position of the comment, you then use “word.Selection.GoTo(WdGoToItem.wdGoToBookmark,Type.Missing,Type.Missing,"B1");” to go to the comment after you open the file. A simple code as below:

        public static void goToBookMark()
        {
            Word.Application word = new Word.Application();
            word.Documents.Open(@"D:\OfficeDev\Word\Edward.docm",true);
            word.Visible = true;            word.Selection.GoTo(WdGoToItem.wdGoToBookmark,Type.Missing,Type.Missing,"B1");
        }
    

    For more information about Selection.GoTo, you could refer the link below:

    Selection.GoTo method: https://msdn.microsoft.com/en-us/library/office/microsoft.office.interop.word.selection.goto(v=office.15).aspx