SoFunction
Updated on 2025-03-06

C# Method to create a Word and open it

This article describes how to create a Word and open it in C#. Share it for your reference. The specific implementation method is as follows:

Copy the codeThe code is as follows:
private static string _createNewWord(string allTnC)
{
    wordDocument = null;
    wordApplication = null;
    string dateTimeNow = ();
    string wordPath = ();
    wordApplication = new ();
    object nothing = ;
    wordDocument = (ref nothing, ref nothing, ref nothing, ref nothing);
    = allTnC;
    object format = ;
    (wordPath, ref format, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing,
 ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing);
    (ref nothing, ref nothing, ref nothing);
    (()wordApplication).Quit(ref nothing, ref nothing, ref nothing);
    return wordPath;
}
private static void _importTnCToActiveDocument(string wordPath)
{
    wordApplication = new ();
    wordDocument = new ();
    Object nothing = ;
    Object filePath = wordPath;
    (ref filePath, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref   nothing, ref   nothing, ref   nothing, ref   nothing, ref  nothing, ref   nothing, ref   nothing);
    wordDocument = ;
    = true;
}

Create ThisAddIn button in vs10-office project to implement certain functions. When multiple words are opened, the current word document object cannot be obtained (such as you need to obtain the bookmark in the first document you opened)

You can add it in Startup:

ViteRibbon viteRibbon = new ViteRibbon();

The constructor passes this parameter and assigns a value:

currentDoucment = ;

I hope this article will be helpful to everyone's C# programming.