Search code examples
c#vbams-wordinteropword-style

VBA "style().LinkToListTemplate ListTemplate := Nothing" in c# word interop


There is a word VBA method "style("style").LinkToListTemplate ListTemplate:=Nothing" which is used to set the style numbering to None. My problem is that I cannot find the same in C# word interop. The method exists but does not work with style.LinkToListTemplate(null).


Solution

  • The LinkToListTemplate method wants a ListTemplate object. VBA isn't so choosy, it figures it out for the developer. The following works for me:

    Word.ListTemplate lt = null;
    styl.LinkToListTemplate(lt); 
    

    Note: While testing I noticed that doing this creates additional ListTemplates in the document. This can be a problem if you do it a lot in the one document. In the version where ListTemplates were introduced (97, as I recall) it could corrupt files, or even crash them. MS fixed that by having Word automatically delete unused LTs when a critical number accumulated. But it can affect file size. Just FYI :-)