1

Hello everyone and sorry for my English: I have this macro that adds a style separator and it works fine, except it adds a blank space in front of the paragraph. How could I modify the macro so that it does not add it, or if it does add it, it removes it later?

Sub SeparadordeEstilos()
 With Selection
            .InsertBefore vbCr
            .InsertStyleSeparator
            .Paragraphs(1).Range.Font.Reset
            .Paragraphs(1).Style = ("PLL Nivel 2 notdc")
End With
End Sub

Edited:

Thank you very much, too, Charles, and my apologies to everyone for not explaining all the details. I need, in an outline multilevel list, two types of paragraphs with the same numbering. Some with a bold font style and that appear in the table of contents and others with a normal font that do not appear in the TOC. So, I have created two styles, PLL Nivel 2 with bold that appears in the TOC and PLL Nivel 2 notdc, without bold, that does not appear in the TOC that is applied automatically with the style separator when executing the macro that I describe in the question . It is the only solution I have found to do it, especially because of the continuous numbering requirement.

Everything works fine except for the white space. This blank space is very bad in the document, it does not give it a professional touch, on the contrary, it gives it a sloppy appearance.

Therefore I need an alternative or to be able to remove the white space.

Screenshot

Here is a sample document with the problem. I thought that consecutive numbering worked fine because I saw it with Show all enabled, but if I turn it off, (Show all), it doesn't work either and sets a different numbering.

Edit 2

Show new picture

  • Could you perhaps save a document with the problem on DropBox or OneDrive and post a view link here. This should be a copy with proprietary or confidential information removed. Indicate where you are trying to add the Style Separator. --- btw Are you on a Mac? – Charles Kenyon Apr 20 '21 at 18:49
  • In addition to the previous comment (we could use a sample), (1) are you talking **vertical** space as in an extra line break, or **horizontal space** as in pressing the spacebar? Are you on a Mac? – Charles Kenyon Apr 21 '21 at 14:36
  • Please, see you the picture and edit. Is Office 2019 for Windows. – wordexperto.com Apr 21 '21 at 14:58
  • I am lazy and busy. Please, please, please provide a sample document with the problem. I do not want to guess and try to set up what you have just to have it not work because I guessed wrong. The screenshot helps, sort of. Is 2.2 supposed to be an unnumbered continuation of 2.1 that will not show up in a Table of Contents? You need your PLL Nivel 2 notdc to not be a numbered style. Numbering should be set up following http://www.shaunakelly.com/word/numbering/numbering20072010.html – Charles Kenyon Apr 21 '21 at 17:35
  • Here is the example. I thought that consecutive numbering worked fine because I saw it with Show all enabled, but if I turn it off, (Show all), it doesn't work either and sets a different numbering. https://1drv.ms/w/s!Ah7fIrE9mm7WphrfqW_jE-nSysH5?e=CYhkhg – wordexperto.com Apr 22 '21 at 07:40
  • I've added a note to my page on Styles about this: http://www.addbalance.com/usersguide/styles.htm#Style_Separators_Numbered – Charles Kenyon Apr 22 '21 at 16:28

2 Answers2

0

vbCr is a new line. This line of code .InsertBefore vbCr insert a new line before your style. Remove it to avoid having a blank space before your paragraph.

Reddy Lutonadio
  • 17,120
  • 4
  • 14
  • 35
0

You want some space, as in the space character, between your two paragraphs!

Your code, when run at the end of a paragraph, before the paragraph mark, adds a style separator and a space with the space being in the new style.

When the line .insertBefore vbCr is omitted, as suggested by Reddy, and it is run at the end of a paragraph, it adds the style separator and a space removing the current paragraph mark and bringing the next paragraph up in the new style so that it appears like a single paragraph using two paragraph styles.

The space is likely needed to apply the style. It is certainly necessary in the second instance to actually separate the text of your first paragraph from that of the second.

Do you really want to eliminate that space?

Here is your macro as revised:

Sub InsertStyleSeparator()
' Use at end of paragraph just before paragraph mark.
    With Selection
        '            .InsertBefore vbCr
        .InsertStyleSeparator
        .Paragraphs(1).range.Font.Reset
        .Paragraphs(1).Style = ("PLL Nivel 2 notdc")
    End With
End Sub

Note the comment I added: Use this at the end of the paragraph, not at the beginning.

Here is your sample document, with the macro.

When used with the style separator, the part that is added to the paragraph does not have its own number. It acts, visually, as part of the paragraph from which it is separated by the style separator.

Charles Kenyon
  • 4,283
  • 2
  • 8
  • 19
  • If the space you are referring to is the extra vertical space or line, you should mark the response by @Reddy Lutonadio as the correct answer. – Charles Kenyon Apr 20 '21 at 18:47
  • I have edited the question, please read it again. – wordexperto.com Apr 21 '21 at 08:48
  • Thank you very much but it doesn't do what I need. I need to change the format of the paragraph, applying a new style, without bold, but keeping the numbering. I have find another way to do it, to use two styles in the same level of multilevel list, using the **Style based on :**. In this way, even though I mark _PLL Nivel 2 notdc_ as based on _PLL Nivel 2_, which is the style linked in level 3 of the multilevel list, when I apply it I can't get the numbering to continue. – wordexperto.com Apr 22 '21 at 14:57
  • When you are using the StyleSeparator, the idea is to have a single logical, visual paragraph. *That would not have a separate number inside the paragraph.* --- If you want numbers within these visual paragraphs you could use a combination of SEQ and StyleRef Fields. – Charles Kenyon Apr 22 '21 at 15:04
  • Here I have uploaded an example similar to what I need that works perfectly. What can be wrong with the First Document? https://1drv.ms/w/s!Ah7fIrE9mm7Wphw9H6tAPhsdxFke?e=LnIVdw. – wordexperto.com Apr 22 '21 at 15:15
  • This one does not use a Style Separator. That makes a difference. Here is a link to your sample document after running your macro. https://www.dropbox.com/s/r5u2b63m6z0gxjq/deleteme%20ejemploquefuncional.docx?dl=0 Paragraph 1.3 is now part of paragraph 1.2 and does not have separate numbering. It has a style separator. – Charles Kenyon Apr 22 '21 at 16:10
  • Here is the same thing without the application of the other style. https://www.dropbox.com/s/tgaqci5996z959l/deleteme%20ejemploquefuncional2.docx?dl=0 That still uses Heading 2 for the included paragraph which has numbering. This messes up the numbering. See both the text and the Table of Contents. Style Separators are not intended to be used to combine two numbered paragraphs and they will not work to do so! – Charles Kenyon Apr 22 '21 at 16:16
  • I am very sorry not to explain the problem well. I need to use two styles at the same level of the multilevel list and this is what I have achieved in the last document **EjemploqueFunciona**. This document is already as I need it and it works perfectly. _Title 2_ is linked to level 2 of the multilevel list and _Title 2 NOBOLD_ is based on _Title 2_, so it works perfectly. This is what I need. My question is: Why doesn't this work in the first **Ejemplo** document, even though _PLL NIvel 2 notdc_ is based on _PLL NIvel 2_ and this, in turn, is linked to level 3 of the multilevel list? – wordexperto.com Apr 22 '21 at 16:45
  • If **Style based on:** works as in **EjemploqueFunciona**, I no longer need the style separator and the macro. Can you make the changes in **Ejemplo** so that when applying _PLL Nivel 2 notdc_ continue the numbering? – wordexperto.com Apr 22 '21 at 16:52
  • Just change that style to be included in your numbering. Base it on a style already numbered. http://shaunakelly.com/word.html You could simply set the first style to use that style for the next paragraph and skip the macro altogether. – Charles Kenyon Apr 22 '21 at 20:53
  • Solved. Thank you very much for the information and for your time. Very thankful – wordexperto.com Apr 23 '21 at 17:04
  • You are welcome. See What should I do when someone answers my question? https://stackoverflow.com/help/someone-answers – Charles Kenyon Apr 23 '21 at 17:08