How to set NoSpaceBetweenParagraphsOfSameStyle in a range RRS feed

  • Question

  • Hi

    In a 2007 word document, I want to set to no space between some paragraphs (not whole document) with VBA.  But Selection.Style.NoSpaceBetweenParagraphsOfSameStyle = True or Selection.Range.Style.NoSpaceBetweenParagraphsOfSameStyle = True effect to whole document.  Any suggjestion?

    Wednesday, March 28, 2012 6:18 PM


All replies

  • In the Word interface, you can apply "No space between paragraphs of the same style" to the selected range. Unfortunately, Microsoft has omitted to add support for this option to the VBA object model. The NoSpaceBetweenParagraphsOfSameStyle property in VBA applies to a style only (and hence to all paragraphs formatted with that style), and there is no way to set this property for a range. (It hasn't been added in Word 2010 VBA either). Sorry!

    Regards, Hans Vogelaar

    Wednesday, March 28, 2012 6:53 PM
  • It is so back for me.  Anyway, Hans, thank you very much for you reply.

    Wednesday, March 28, 2012 8:31 PM
  • You can do this using the format paragraph dialog, which works on the Selection ...
        With Dialogs(wdDialogFormatParagraph)
            ..NoSpaceBetweenParagraphsOfSameStyle = 1
        End With

    Friday, March 30, 2012 12:59 PM
  • Tony, that's great! (I assume that you intended one dot before the lines in the middle instead of two dots)

    Regards, Hans Vogelaar

    Friday, March 30, 2012 1:06 PM
  • Yes, Hans, I think it's the Bridge that adds the extra dots.

    Friday, March 30, 2012 3:05 PM
  • Hi Tony

    It doesn't work for me.  I'm using Office 2007.  I searched in MSDN.  In this page, it shows NoSpaceBetweenParagraphsOfSameStyle is not in the argument list of wdDialogFormatParagraph.  Do I still miss something?

    Friday, March 30, 2012 4:32 PM
  • That MSDN page is for Word 2002 (aka XP). The one for Word 2007,, does mention it:

    Did you change the double dots to single ones?

        With Dialogs(wdDialogFormatParagraph)
            .NoSpaceBetweenParagraphsOfSameStyle = 1
        End With

    Regards, Hans Vogelaar

    Friday, March 30, 2012 4:43 PM
  • Thanks Tony and Hans.  It works in another machina but not in my machina.  So I have to repair my Office first.
    Friday, March 30, 2012 5:49 PM