Producing Word document with windows form, doesn't work for all PCs: System.Runtime.InteropServices.COMException (0x800A16CA)

TRIACCA Marco 101 Reputation points
2020-11-24T11:33:54.547+00:00

Hello,

I developed a windows form app to produce Word reports. At the beginning it worked fine on all the PCs producing well done documents, after I added the following chunk of code it stopped to produce the reports when executed on some PCs.

                    object end = 0;
                    object start = 0;
                    string title = Regex.Replace(tab.Cell(1, 1).Range.Text, pattern, dati[7]);
                    Range rng = doc.Range(ref start, ref end);
                    rng.Text = title;
                    Object styleHeading2 = "Heading 2";
                    rng.set_Style(ref styleHeading2);
                    rng.Paragraphs.OutlineLevel = Word.WdOutlineLevel.wdOutlineLevel2;
                    rng.Paragraphs.SpaceAfter = 10;

I found that, on the PCs where it doesn' work, the code throws the following exception:
System.Runtime.InteropServices.COMException (0x800A16CA): the item with the specified name does not exist.
in Microsoft.office.Interop.Word.Range.set_style(Object& prop)

Do you have any idea to solve it??

thank you

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,839 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,126 questions
{count} votes

Accepted answer
  1. TRIACCA Marco 101 Reputation points
    2020-11-25T11:20:23.617+00:00

    The problem was about Word's language. On my pc Word is in english, but my colleagues have native language Word thus they don't understand the command:

    Object styleHeading2 = "Heading 2";
    

    The solution is to set style using Word.WdBuiltinStyle enumeration, in this case:

    Object styleHeading2 = WdBuiltinStyle.wdStyleHeading2;
    
    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Dave Patrick 426.1K Reputation points MVP
    2020-11-24T14:44:20.43+00:00

    Might also try them over here.
    https://social.msdn.microsoft.com/Forums/en-US/home?forum=vsto
    https://social.msdn.microsoft.com/Forums/en-US/home?forum=officegeneral

    --please don't forget to Accept as answer if the reply is helpful--

    0 comments No comments