Search code examples
c#ms-wordinteropoffice-interopword-interop

How to find the "replace text as you type" in Word AutoCorrect option in Word with C#


I'm trying to check whether the word "CU" is exist in "word replace text list". I found out in interop.Excel and in VBA, we have AutoCorrect.ReplacementList. But in interop.Word is not.

So my question is how do i can check "CU" exist in Word replacement list by C#. Thanks for your watching. enter image description here

Microsoft.Office.Interop.Word.Application oWord = (Microsoft.Office.Interop.Word.Application)w;
_activeDoc = oWord.ActiveDocument;
oWord.Application.AutoCorrect.ReplaceText .......??????

Solution

  • To get a list of the AutoCorrect listing in Word use the AutoCorrect.Entries collection. The Name property returns the "shortcut", the Value property the text that replaces the "shortcut".

    string acName = "";
    string acValue = "";
    bool foundit = false;
    Word.AutoCorrectEntries ACs = wdApp.AutoCorrect.Entries;
    foreach (Word.AutoCorrectEntry AC in ACs)
    {
        acName = AC.Name;
        acValue = AC.Value;
        Debug.Print("Name: {0}, Value: {1}", acName, acValue);
        if (acName == "CU")
        {
            foundit = true;
            break;
        }
    }
    if (foundit)
    {
        MessageBox.Show("Found it: " + acValue);
    }
    else MessageBox.Show("Not present");