none
Style problem RRS feed

  • Question

  • We have a template with a style called "Paragraph". The following code applies that style to the selected pragraph in any document which uses that template.

    Selection.Style = ActiveDocument.Styles("Paragraph")

    We have a TEX file opened using tex2word. (Very succesfully). We apply our template to that file using

      With ActiveDocument
        .UpdateStylesOnOpen = True
        .AttachedTemplate = mytemplate
      End With

    However when you do

    Selection.Style = ActiveDocument.Styles("Paragraph")

    A style called "Heading4,Paragraph" is applied and the stlye "Paragraph" cannot be found in the document.

    1. Why has the style "Paragraph" disappeared.

    2. Why does "Selection.Style = ActiveDocument.Styles("Paragraph") " not give an error?

    We have tried renaming "Heading4,Paragraph" to "Paragraph" but when you click on OK the new name reverts to "Heading4,Paragraph"

    Any suggestions?

    Thursday, July 11, 2013 1:53 PM

Answers

  • I'm going to assume you're working with version 2007 or later...

    Display the Styles task pane. Right-click on the entry "Heading 4, Paragraph". Select the command "Modify".

    At the top of the dialogbox you should see the name of the style: Heading 4, Paragraph.

    Delete the comma (or semicolon) and everything that follows it.


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, July 15, 2013 3:24 PM
    Moderator

All replies

  • Try first attaching the template, then updating the styles. In the order you have things, the styles are being updated from whatever template is previously attached to the file/document.

    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, July 11, 2013 2:02 PM
    Moderator
  • Thanks for the suggestion. We tried that and it made no difference.

    Friday, July 12, 2013 7:21 AM
  • Is this problem happening only with the one file? Is it possible that this file already contains a style of that name, linked to Heading 4?


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, July 12, 2013 11:09 AM
    Moderator
  • Yes, that is likely. How do we unlink the two styles?

    Friday, July 12, 2013 11:12 AM
  • Delete the Paragraph style from the document. Since you say this is a TEX file, I can't provide you with any details on how that would be done - I'm not familiar with such files.

    Cindy Meister, VSTO/Word MVP, my blog

    Friday, July 12, 2013 11:41 AM
    Moderator
  • hi keytecstaff2012,

    I created a word template with a style named 'Paragraph'. Attached the template after opening a word. Then I set the style for a range object. The code was successful.

    First, I suggest you to open an real word file for testing.

    Second, check if your template attached successfully. After attached successfully, you can see the 'Paragraph' style.

    Third, you can write code like this 'Selection.Style = ThisDocument.Styles("Paragraph")' after attach template successfully. Because the activeDocument may be not the document you attach the tempalte when you open a new word. If a named 'Paragraph' in your ActiveDocument, there is no error message.

     

    Monday, July 15, 2013 8:20 AM
  • There is no style in the document called "Paragraph".

    When you do

    Selection.Style = ActiveDocument.Styles("Paragraph")

    the style "Heading4,Paragraph" is applied.

    When you try to delete "Heading4,Paragraph" you cannot do so because it claims to be a built in style.

    I should not have mentioned TEX files. This is not relevant because by the time we have got to this stage in our process the file is Word document (and has been saved as in docx format.

    Monday, July 15, 2013 9:27 AM
  • I'm going to assume you're working with version 2007 or later...

    Display the Styles task pane. Right-click on the entry "Heading 4, Paragraph". Select the command "Modify".

    At the top of the dialogbox you should see the name of the style: Heading 4, Paragraph.

    Delete the comma (or semicolon) and everything that follows it.


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, July 15, 2013 3:24 PM
    Moderator
  • Thanks, that did the trick.

    Once We had modified the name of the style to "Heading4" we were able to re-apply our template and the style "Paragraph" was now available.

    Tuesday, July 16, 2013 2:11 PM