Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-27-2023, 09:40 AM
RobiNew RobiNew is offline Paragraph Dialog: No Space Between Paragraphs of Same Style Windows 10 Paragraph Dialog: No Space Between Paragraphs of Same Style Office 2016
Competent Performer
Paragraph Dialog: No Space Between Paragraphs of Same Style
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Question Paragraph Dialog: No Space Between Paragraphs of Same Style

I have been working on the following macro to unselect 'NoSpaceBetweenParagraphsOfSameStyle' for all paragraphs (text and footnotes), but the code does not work correctly. Please help! Thanks!



Quote:
Sub NoSpaceBetweenPar()
Dim aRng As Range, iType As Integer
Dim Para As Paragraph
On Error GoTo Leave 'if no footnotes
For iType = 1 To 2
Set aRng = ActiveDocument.StoryRanges(iType) 'wdMainTextStory = 1, wdFootnotesStory = 2
For Each Para In ActiveDocument.Paragraphs
With Para.Range
With Dialogs(wdDialogFormatParagraph)
.NoSpaceBetweenParagraphsOfSameStyle = False
.Execute
End With
End With
Next
Next iType


Leave:
End Sub
Reply With Quote
  #2  
Old 09-27-2023, 12:46 PM
vivka vivka is offline Paragraph Dialog: No Space Between Paragraphs of Same Style Windows 7 64bit Paragraph Dialog: No Space Between Paragraphs of Same Style Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Hi! I think you will find the answers here:
Style.NoSpaceBetweenParagraphsOfSameStyle Always Returning False?
and
NoSpaceBetweenParagraphsOfSameStyle

Using Graham Mayor's advice, I've slightly changed your code and it seems to work:

Sub NoSpaceBetweenPar()
Dim aRng As range, iType As Integer
Dim Para As Paragraph

On Error GoTo Leave 'if no footnotes
For iType = 1 To 2
Set aRng = ActiveDocument.StoryRanges(iType)
For Each Para In aRng.Paragraphs
Para.Style.NoSpaceBetweenParagraphsOfSameStyle = False
Next Para
Next iType
Leave:
End Sub
Reply With Quote
  #3  
Old 09-27-2023, 08:18 PM
Guessed's Avatar
Guessed Guessed is offline Paragraph Dialog: No Space Between Paragraphs of Same Style Windows 10 Paragraph Dialog: No Space Between Paragraphs of Same Style Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

This setting belongs in the paragraph style so you should be looping through the styles and doing this to all paragraph styles.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #4  
Old 09-28-2023, 02:52 AM
RobiNew RobiNew is offline Paragraph Dialog: No Space Between Paragraphs of Same Style Windows 10 Paragraph Dialog: No Space Between Paragraphs of Same Style Office 2016
Competent Performer
Paragraph Dialog: No Space Between Paragraphs of Same Style
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default

Thanks a lot to both of you for your comments! However, Vivka's new code does not work for me. Any idea?
Reply With Quote
  #5  
Old 09-28-2023, 07:47 AM
RobiNew RobiNew is offline Paragraph Dialog: No Space Between Paragraphs of Same Style Windows 10 Paragraph Dialog: No Space Between Paragraphs of Same Style Office 2016
Competent Performer
Paragraph Dialog: No Space Between Paragraphs of Same Style
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default

Hi! It's almost incredible. Vivka's code sometimes works and sometimes doesn't. No other way to do it? With 'Content'? Thanks!
Reply With Quote
  #6  
Old 09-28-2023, 08:17 AM
vivka vivka is offline Paragraph Dialog: No Space Between Paragraphs of Same Style Windows 7 64bit Paragraph Dialog: No Space Between Paragraphs of Same Style Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Hi, RobiNew! Sorry but I have no other ideas than trying replacing

For Each Para In aRng.Paragraphs
with
For Each Para In ActiveDocument.range.Paragraphs.
Reply With Quote
  #7  
Old 09-28-2023, 08:50 AM
RobiNew RobiNew is offline Paragraph Dialog: No Space Between Paragraphs of Same Style Windows 10 Paragraph Dialog: No Space Between Paragraphs of Same Style Office 2016
Competent Performer
Paragraph Dialog: No Space Between Paragraphs of Same Style
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default

Sorry, no improvement. It never worked. The other sometimes did.
Reply With Quote
  #8  
Old 10-01-2023, 07:02 AM
RobiNew RobiNew is offline Paragraph Dialog: No Space Between Paragraphs of Same Style Windows 10 Paragraph Dialog: No Space Between Paragraphs of Same Style Office 2016
Competent Performer
Paragraph Dialog: No Space Between Paragraphs of Same Style
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default

Hi Vivka! The code here below works ALWAYS. Thank you for your suggestions!



Quote:
Sub NoSpaceBetweenPara()
Dim aRng As Range, iType As Integer
Dim Para As Paragraph
On Error GoTo Leave 'if no footnotes
For iType = 1 To 2
Set aRng = ActiveDocument.StoryRanges(iType)
ActiveDocument.StoryRanges.Item(iType).Select
With Dialogs(wdDialogFormatParagraph)
.NoSpaceBetweenParagraphsOfSameStyle = False
.Execute
End With
Next
Selection.HomeKey Unit:=wdStory
Leave:
End Sub
Reply With Quote
  #9  
Old 10-01-2023, 07:52 AM
vivka vivka is offline Paragraph Dialog: No Space Between Paragraphs of Same Style Windows 7 64bit Paragraph Dialog: No Space Between Paragraphs of Same Style Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Hi, RobiNew, and thank you for sharing your workable code! It's nice to learn something new!
Reply With Quote
Reply

Tags
dialog, paragraphs, space



Similar Threads
Thread Thread Starter Forum Replies Last Post
Paragraph Dialog: No Space Between Paragraphs of Same Style Remove extra space before a paragraph and return it to previous paragraph laith93 Word VBA 7 04-27-2022 08:26 AM
a macro to replace paragraph mark with a space applies effect on paragraph marks after the selection drrr Word VBA 2 08-24-2021 03:05 AM
Paragraph Dialog: No Space Between Paragraphs of Same Style In 2010 document set for no space between paragraphs, but getting large space. normancamp Word 10 12-25-2017 04:54 PM
"Don't add space between paragraphs of the same style" within tables WordUser789 Word Tables 3 12-17-2017 05:02 PM
Allowing space between paragraphs of same style jjmclell Word VBA 4 04-02-2015 06:44 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:32 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft