locked
Locally sharing a Microsoft Word Document (for testing purposes) RRS feed

  • Question

  • I am currently testing an application based upon automating Microsoft Word.

    The application does not edit a Word Document. Rather is extracts user selected text from the document

    I would like to automate the testing. That is create an application which serves to select the text that will subsequently be extracted by the application

    How does one locally share (ie no use of the Cloud or SharePoint) a Word Document (if at all)?

    Thursday, November 7, 2019 1:31 PM

All replies

  • The simplest approach is to simply put the document on a network share to which all collaborators have access.

    If the document should serve as an unchanging source during testing, you can make a network share into a Workgroup Templates folder. You would access the document using File>New>Custom>Workgroup Templates. The document will be treated like a template, with a new document spawned from the original. Here's my article explaining Workgroup Templates in Office: Shared Workgroup Templates - Best Practices

    Thursday, November 7, 2019 3:34 PM
  • Hi,

    Please refer to jkorchok’s reply to have a check. Please remember to mark the reply as answer if it is helpful. Your action would help other users who encounter the same issue find the correct forum for help quickly when they read this thread. Thank you for understanding!

    If you have any updates, please feel free to let me know.

    Best Regards,

    Emily


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Office 2019.

    Friday, November 8, 2019 6:59 AM
  • Using a network share is not an option

    Using templates is not an option

    Saturday, November 9, 2019 12:52 AM
  • I discovered a strategy which works for text selection

    In C#

       static void UnitUnderTest()
       {
          object oMissing = System.Reflection.Missing.Value;
          Microsoft.Office.Interop.Word.Application oWord = null;
          Microsoft.Office.Interop.Word.Document oDocument;
          Microsoft.Office.Interop.Word.Paragraph oPara1;
          string text;

          oWord = new Microsoft.Office.Interop.Word.Application();
          oWord.Visible = true;
          oDocument = oWord.Documents.Add();
          oDocument = oWord.ActiveDocument;
          oPara1 = oDocument.Content.Paragraphs.Add(ref oMissing);
          oPara1.Range.Text = "0123456789";
          oPara1.Range.Font.Bold = 1;
          oPara1.Format.SpaceAfter = 24;    //24 pt spacing after paragraph.
          oPara1.Range.InsertParagraphAfter();

          // wait for the test driver to make a selection

          text = oWord.Selection.Text;
       }

       static void TestDriver()
       {
          object oMissing = System.Reflection.Missing.Value;
          Microsoft.Office.Interop.Word.Application oWord = null;
          Microsoft.Office.Interop.Word.Window oWindow;
          Microsoft.Office.Interop.Word.Document oDocument;
          Microsoft.Office.Interop.Word.Documents oDocuments;

          object temp;
          string strApplicationToOpen = "Word.Application";
          temp = System.Runtime.InteropServices.Marshal.GetActiveObject(strApplicationToOpen);
          oWord = temp as Microsoft.Office.Interop.Word.Application;

          oWindow = oWord.Windows[1];
          oWindow.Activate();
          oDocuments = oWord.Documents;
          oDocument = oDocuments[1];
          oDocument.Range(5, 9).Select();
       }

    Saturday, November 9, 2019 2:28 PM
  • Hi,

    Thanks for your response and sharing.

    This forum focuses more on general questions related to Word application for IT administrators, instead of developers. In general, we could share the files in local area network in addition to Cloud like OneDrive.

    For C#, it is out of my support scope, I'd like to suggest you post a new question to some forums about C# code. You may get more replies there about sharing Word documents. Thanks you for you kind understanding.

    If you have any solutions, please feel free to let me know and mark your replies as answers. Your action would be helpful to other users who encounter the same issue and read this thread. Thanks for your understanding.

    Best Regards,

    Emily


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Office 2019.

    Monday, November 11, 2019 9:18 AM
  • Hi,

    I am checking the status of this issue. Do you have any update for it?

    Anything unclear or any questions, feel free to post them back to let us know. I will be glad to follow up and help you.

    Best Regards,

    Emily


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Office 2019.

    Thursday, November 14, 2019 12:44 AM
  • Hi,

    Thanks for your sharing about your solution. Here I will provide a brief summary of this post for your information.

    ====================

    Request/Expectation:

    Sharing Word documents locally not via network, templates or Clouds (Such as OneDrive).

    ====================

    Solution Summary:

    In C#

       static void UnitUnderTest()
       {
          object oMissing = System.Reflection.Missing.Value;
          Microsoft.Office.Interop.Word.Application oWord = null;
          Microsoft.Office.Interop.Word.Document oDocument;
          Microsoft.Office.Interop.Word.Paragraph oPara1;
          string text;

          oWord = new Microsoft.Office.Interop.Word.Application();
          oWord.Visible = true;
          oDocument = oWord.Documents.Add();
          oDocument = oWord.ActiveDocument;
          oPara1 = oDocument.Content.Paragraphs.Add(ref oMissing);
          oPara1.Range.Text = "0123456789";
          oPara1.Range.Font.Bold = 1;
          oPara1.Format.SpaceAfter = 24;    //24 pt spacing after paragraph.
          oPara1.Range.InsertParagraphAfter();

          // wait for the test driver to make a selection

          text = oWord.Selection.Text;
       }

       static void TestDriver()
       {
          object oMissing = System.Reflection.Missing.Value;
          Microsoft.Office.Interop.Word.Application oWord = null;
          Microsoft.Office.Interop.Word.Window oWindow;
          Microsoft.Office.Interop.Word.Document oDocument;
          Microsoft.Office.Interop.Word.Documents oDocuments;

          object temp;
          string strApplicationToOpen = "Word.Application";
          temp = System.Runtime.InteropServices.Marshal.GetActiveObject(strApplicationToOpen);
          oWord = temp as Microsoft.Office.Interop.Word.Application;

          oWindow = oWord.Windows[1];
          oWindow.Activate();
          oDocuments = oWord.Documents;
          oDocument = oDocuments[1];
          oDocument.Range(5, 9).Select();
       }

    This solution provieded by DavidLightstone.

    ====================

    Reference Links:

    No.

    ====================

    Best Regards,

    Emily


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Office 2019.

    Wednesday, November 27, 2019 1:14 AM