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

6
  • 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? Apr 20, 2021 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? Apr 21, 2021 at 14:36
  • Please, see you the picture and edit. Is Office 2019 for Windows. Apr 21, 2021 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 shaunakelly.com/word/numbering/numbering20072010.html Apr 21, 2021 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. 1drv.ms/w/s!Ah7fIrE9mm7WphrfqW_jE-nSysH5?e=CYhkhg Apr 22, 2021 at 7:40

2 Answers 2

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.

12
  • 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. Apr 20, 2021 at 18:47
  • I have edited the question, please read it again. Apr 21, 2021 at 8: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. Apr 22, 2021 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. Apr 22, 2021 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? 1drv.ms/w/s!Ah7fIrE9mm7Wphw9H6tAPhsdxFke?e=LnIVdw. Apr 22, 2021 at 15:15
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.

1
  • Thank you. It does not add the space but changes the numbering. I use it in numbered lists. Apr 20, 2021 at 18:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.