Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-23-2023, 09:21 AM
RobiNew RobiNew is offline Get rid of leading spaces before paragraphs in the footnote section Windows 10 Get rid of leading spaces before paragraphs in the footnote section Office 2016
Competent Performer
Get rid of leading spaces before paragraphs in the footnote section
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Question Get rid of leading spaces before paragraphs in the footnote section

Years ago Macropod suggested two methods to remove leading spaces before paragraphs, with Wildcard Find/Replace, where:
1. Find =^13[ ]{1,}
'Replace = ^p
OR
2. 'Find = [ ]{1;}([!^13]@^13)
'Replace = \1
These two methods are perfect for the text of a document, but have no effect in the footnote sector. Any idea? Thanks!
Reply With Quote
  #2  
Old 10-23-2023, 11:51 AM
vivka vivka is offline Get rid of leading spaces before paragraphs in the footnote section Windows 7 64bit Get rid of leading spaces before paragraphs in the footnote section Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Hi, Robinew! The Macropod's code does work on footnotes! I've checked it. Try replacing {1;} with {1,}, just in case.
Code:
Sub Del_Spaces_Starting_Paras()
'In selection, delete spaces & unbr spaces starting paragraphs
'including the doc's 1st paragraph.

Dim myRng As range
    
Application.ScreenUpdating = False
  Set myRng = ActiveDocument.StoryRanges(2)
    selection.Find.ClearFormatting
    selection.Find.Replacement.ClearFormatting
    With myRng.Find
        .text = "[^32^s]{1;}([!^13]@^13)"
        .Replacement.text = "\1"
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchWildcards = True
        .Execute Replace:=wdReplaceAll
    End With
Application.ScreenUpdating = True
End Sub

Last edited by vivka; 10-24-2023 at 06:17 AM.
Reply With Quote
  #3  
Old 10-23-2023, 11:30 PM
RobiNew RobiNew is offline Get rid of leading spaces before paragraphs in the footnote section Windows 10 Get rid of leading spaces before paragraphs in the footnote section Office 2016
Competent Performer
Get rid of leading spaces before paragraphs in the footnote section
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default

Thanks, Vivka! Unfortunately, it does non work for me. The line of code With myRng.Find{1;} produces a syntax error or invalid character (also with {1,} ). Any idea?
Reply With Quote
  #4  
Old 10-24-2023, 06:13 AM
vivka vivka is offline Get rid of leading spaces before paragraphs in the footnote section Windows 7 64bit Get rid of leading spaces before paragraphs in the footnote section Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Sorry, RobiNew! Of course it was a gross mistake of mine! I for an unknown reason put {1;} in a wrong place! I have corrected the code. Please, try it.
Reply With Quote
  #5  
Old 10-24-2023, 07:39 AM
RobiNew RobiNew is offline Get rid of leading spaces before paragraphs in the footnote section Windows 10 Get rid of leading spaces before paragraphs in the footnote section Office 2016
Competent Performer
Get rid of leading spaces before paragraphs in the footnote section
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default

Hi, Vivka! Sorry, but it doesn't work in the footnote sector. It works only in the text sector, if I change (2) to (1). Thanks!
Reply With Quote
  #6  
Old 10-24-2023, 09:01 AM
vivka vivka is offline Get rid of leading spaces before paragraphs in the footnote section Windows 7 64bit Get rid of leading spaces before paragraphs in the footnote section Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

The only idea that occurs to me is that probably you have tabs starting paragraphs. Try replacing
.text = "[^32^s]{1;}([!^13]@^13)"
with
.text = "[^32^s^9]{1;}([!^13]@^13)"
Reply With Quote
  #7  
Old 10-24-2023, 09:48 AM
RobiNew RobiNew is offline Get rid of leading spaces before paragraphs in the footnote section Windows 10 Get rid of leading spaces before paragraphs in the footnote section Office 2016
Competent Performer
Get rid of leading spaces before paragraphs in the footnote section
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default

No, there are no tabs before the footnote paragraphs. I've tried the code on several docs and on the one I'm attaching. Thanks!
Attached Files
File Type: docx NewTest.docx (44.6 KB, 1 views)
Reply With Quote
  #8  
Old 10-24-2023, 10:11 AM
vivka vivka is offline Get rid of leading spaces before paragraphs in the footnote section Windows 7 64bit Get rid of leading spaces before paragraphs in the footnote section Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Code:
Sub Space_Starting_Paras_Del_1()
'In footers, delete spaces, unbr spaces & tabs starting paras.

Dim myRng As range
    
Application.ScreenUpdating = False

  Set myRng = ActiveDocument.StoryRanges(2)
    selection.Find.ClearFormatting
    selection.Find.Replacement.ClearFormatting
    With myRng.Find
        .text = "[^32^s^9]{1;}([!^13]@^13)"
        .Replacement.text = "\1"
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchWildcards = True
        .Execute Replace:=wdReplaceAll
        .text = "[^13]{2;}"
        .Replacement.text = ""
        .Execute Replace:=wdReplaceAll
    End With
 Application.ScreenUpdating = True
Set myRng =Nothing
 End Sub
Reply With Quote
  #9  
Old 10-24-2023, 02:22 PM
RobiNew RobiNew is offline Get rid of leading spaces before paragraphs in the footnote section Windows 10 Get rid of leading spaces before paragraphs in the footnote section Office 2016
Competent Performer
Get rid of leading spaces before paragraphs in the footnote section
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default

Many thanks, Vivka! But the new version does not work in the footnote sector. In docs with large/normal paragraphs it damages the text of the main sector. Obviously with (2) > (1).
Reply With Quote
  #10  
Old 10-25-2023, 03:45 AM
vivka vivka is offline Get rid of leading spaces before paragraphs in the footnote section Windows 7 64bit Get rid of leading spaces before paragraphs in the footnote section Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Hi, RobinNew! The last macro is only for footnotes! If used on storyrange(1) that has empty paragraphs, it will merge the paragraphs. On the other hand, the macro that is always good for storyrange(1) won't be good for storyrange(2). I suggest you combine two codes in one: the first one for the main body/active document followed by the other one for footnotes. I could not make a code based on Find-Replace that would be good for both storyranges.

My combination:
Code:

Sub Del_Spaces_Starting_Paras()
 'In the doc's main body and footnotes, delete spaces starting paras.

Dim myRng As range
    
Application.ScreenUpdating = False

'Work on active doc/main body:
  Set myRng = ActiveDocument.StoryRanges(1)
    selection.Find.ClearFormatting
    selection.Find.Replacement.ClearFormatting
    With myRng.Find
        .text = "[^32^s^9]{1;}([!^13]@^13)"
'Or:
'        .text = "[^32^s^9]{1;}(*^13)"
        .Replacement.text = "\1"
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchWildcards = True
        .Execute Replace:=wdReplaceAll
    End With
    Set myRng = ActiveDocument.StoryRanges(2)
    With myRng.Find
        .text = "[^32^s^9]{1;}([!^13]@^13)"
'Or:
'        .text = "[^32^s^9]{1;}(*^13)"
        .Replacement.text = "\1"
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchWildcards = True
        .Execute Replace:=wdReplaceAll
        .text = "[^13]{2;}"
        .Replacement.text = ""
        .Execute Replace:=wdReplaceAll
    End With
  Application.ScreenUpdating = True
  Set myRng = Nothing
 End Sub
Or use the following code, which is not as fast as the Find_Replace code, but it is quite simple;

Sub Spaces_Starting_Paras_Del()
'In the doc's main body and footnotes, delete spaces starting paras.

Application.ScreenUpdating = False

For i = 1 To 2
For Each Para In ActiveDocument.StoryRanges(i).Paragraphs
Do While Para.range.Characters.First = Chr(32)
Para.range.Characters.First.Delete
Loop
Next Para
Next i
Application.ScreenUpdating = True
End Sub
Reply With Quote
  #11  
Old 10-25-2023, 06:10 AM
RobiNew RobiNew is offline Get rid of leading spaces before paragraphs in the footnote section Windows 10 Get rid of leading spaces before paragraphs in the footnote section Office 2016
Competent Performer
Get rid of leading spaces before paragraphs in the footnote section
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default

Hi, Vivka! I know that your last macro was only for footnotes! I was just reporting experiments. However, the (2)-macro does not work for me in the footnote sector. I have adopted your simple macro, which actually works for both sectors: text and footnotes. Many, many thanks!
Reply With Quote
  #12  
Old 10-25-2023, 06:31 AM
vivka vivka is offline Get rid of leading spaces before paragraphs in the footnote section Windows 7 64bit Get rid of leading spaces before paragraphs in the footnote section Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Thank you, RobiNew for the possibility to experiment and learn new things!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Get rid of leading spaces before paragraphs in the footnote section Footnote references in the footnote section losing their style when cut+pasted from same doc emblaw Word 4 12-08-2020 06:23 AM
Get rid of leading spaces before paragraphs in the footnote section Find and Replace/Insert 'CR', delete leading Spaces wherever a user Clicks in a Word document DavidL Word VBA 7 04-04-2018 12:01 AM
Get rid of leading spaces before paragraphs in the footnote section How to remove trailing & leading spaces in a cell? LearnerExcel Excel Programming 8 02-04-2018 08:22 PM
Get rid of leading spaces before paragraphs in the footnote section Removing indentations at beginning of paragraphs and replacing with line spaces captainamerica Word 2 10-27-2017 05:32 PM
Get rid of leading spaces before paragraphs fig000 Word 11 03-14-2016 01:59 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:48 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