Word2010 - Programatically apply template styles to numbered lists
-
Friday, March 23, 2012 1:28 AM
I am building a Word 2010 VSTO addin using VS2010 which constructs a document from stored snippets. The created document needs to be branded differently according to the business unit creating the dicument.
I acheive the rebranding by selecting an appropriate template which has the styles I need and then issuing document.CopyStylesFromTemplate. The styles in each of the templates are identrically named which means that the output dcument is (almost) successfully rebranded.
The issue I am facing is the numbered lists contained within the snippets do not have the styles updated and do not then appear in the required branding. I have looked far and wide across this site and others and confirmed that CopyStylesFromTemplate does not update the list styles.
I have tried various ways to do it, all to no avail.
I would greatly appreciate some help to solve this issue.
Thanks in Advance !
All Replies
-
Friday, March 23, 2012 2:27 AMHave you tried ActiveDocument.UpdateStyles when the source template is attached to the document? Here's an article, it's old but updated just last year, so it might still apply and help. http://word.mvps.org/faqs/macrosvba/UpdateStyles.htm
Kind Regards, Rich ... http://greatcirclelearning.com
- Edited by Rich Michaels Friday, March 23, 2012 2:28 AM
-
Friday, March 23, 2012 2:37 AM
Hi Rich,
Yes I have tried that, it still has the same issue of not applying to the styles of the numbered lists :(
-
Tuesday, March 27, 2012 6:20 AMModerator
Hi PalerSash,
Would you please show your snippet to me for further research?
Have a good day,
Tom
Tom Xu [MSFT]
MSDN Community Support | Feedback to us
-
Monday, April 02, 2012 6:18 PMModerator
Hi PalerSash,
I don't have your experience. I have two templates, one where the style for the numeric list specifies red font and one for the style for the numeric list specifies green font. In the snippet below I use "WordTemplateList11.dotx" and see red font, and the retest using "WordTemplateList12.dotx" where I see green font.
The environment is Office 2010 32-bit on Windows 7 32-bit, using Visual Studio 2010.namespace WordListStyles { public partial class ThisAddIn { private void ThisAddIn_Startup(object sender, System.EventArgs e) { Word.Document doc; doc = Application.Documents.Open(@"C:\Users\<user>\Documents\ListStyles Test.docx"); doc.CopyStylesFromTemplate("C:\\Program Files\\Microsoft Office\\Templates\\WordTemplateList12.dotx"); } private void ThisAddIn_Shutdown(object sender, System.EventArgs e) { }The document looks like thisListStyles Test
On the Insert tab, the galleries include
items that are designed to coordinate with the overall look of your document.- Item 1
- Item 2
- Item 3
On the Insert tab, the galleries include
items that are designed to coordinate with the overall look of your document.
You can use these galleries to insert tables, headers, footers, lists, cover
pages, and other document building blocks.Tom Xu asked "Would you please show your snippet to me for further research?" If your snippet is very similar to mine (above), instead of asking you to show your snippet, please try code similar to that above and let us know the results. This means modifying the name and location of the document and of the template, and assumes your environment is equivalet to mine.
Regards,
Chris Jensen
Senior Technical Support Lead
Chris Jensen

