Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-06-2023, 11:35 PM
RobiNew RobiNew is offline Remove spaces before each paragraph mark in text and footnotes Windows 10 Remove spaces before each paragraph mark in text and footnotes Office 2016
Competent Performer
Remove spaces before each paragraph mark in text and footnotes
 
Join Date: Sep 2023
Posts: 208
RobiNew is on a distinguished road
Question

Hi Vivka! Of course I will post an example of my text, but first I'd like to ask you again: since my footnotes do not contain multiple spaces, but only one space before the only ^p at the end, couldn't you simply modify the code here below so as to delete the space instead of inserting it? Thanks!



Code:
Sub InsertSpace()
Dim aRng As Range
Dim iType As Integer
Dim Para As Paragraph
  For iType = 1 To 2
Set aRng = ActiveDocument.StoryRanges(iType)
For Each Para In aRng.Paragraphs
Para.Range.Characters.Last.InsertBefore " "
Next Para
Next iType
Set aRng = Nothing
End Sub
Reply With Quote
  #2  
Old 10-07-2023, 12:46 AM
vivka vivka is offline Remove spaces before each paragraph mark in text and footnotes Windows 7 64bit Remove spaces before each paragraph mark in text and footnotes Office 2016
Expert
 
Join Date: Jul 2023
Posts: 302
vivka is on a distinguished road
Default

Hi, RobiNew! It's quite simple:
replace:
Para.range.Characters.Last.InsertBefore " "
with:
Para.range.Characters.Last.Previous.Delete

But this method deletes any (not anly space!) before the para sign and it is not the fastest one. To delete only spaces, the following condition should be included, which also will make the code a millisecond slower:
If Para.range.Characters.Last.Previous = " " Then
Para.range.Characters.Last.Previous.Delete
End If


RobiNew, I really can't understand why the code from post 9 doesn't work for you! I have retested it this morning again - and no problem! I'm eager to see your footnote!
Reply With Quote
  #3  
Old 10-07-2023, 02:20 AM
RobiNew RobiNew is offline Remove spaces before each paragraph mark in text and footnotes Windows 10 Remove spaces before each paragraph mark in text and footnotes Office 2016
Competent Performer
Remove spaces before each paragraph mark in text and footnotes
 
Join Date: Sep 2023
Posts: 208
RobiNew is on a distinguished road
Default

Hi Vivka! Thank you for your patience. I'm attaching a test file with footnotes.
Attached Files
File Type: docx TEST_TEST.docx (41.3 KB, 13 views)
Reply With Quote
  #4  
Old 10-07-2023, 05:35 AM
vivka vivka is offline Remove spaces before each paragraph mark in text and footnotes Windows 7 64bit Remove spaces before each paragraph mark in text and footnotes Office 2016
Expert
 
Join Date: Jul 2023
Posts: 302
vivka is on a distinguished road
Default

Hi, RobiNew! This is a workaround to delete spaces ending paragraphs only in footnotes but it is the fastest method:
Code:
Sub Footnotes_Spaces_Del()
'In the doc's footnotes, delete spaces ending paragraphs.

Dim oRng As range

Application.ScreenUpdating = False
    Set oRng = ActiveDocument.StoryRanges(2)
    With oRng.Find
       .ClearFormatting
       .Replacement.ClearFormatting
'Find one space and an invisible paragraph sign:
       .text = " ^p"
 'Add an extra space (or more in case there are extra spaces elsewhere in footnotes)
'before a paragraph end (note that the para sign is absent here!):
       .Replacement.text = "  "
       .MatchWildcards = False
       .Execute Replace:=wdReplaceAll
    End With
    With oRng.Find
'Find more than one space (in case of error, replace ; with comma):
       .text = Chr(32) & "{2;}"
'Delete them:
       .Replacement.text = ""
       .MatchWildcards = True
       .Execute Replace:=wdReplaceAll
     End With
 Application.ScreenUpdating = True
Set oRng = Nothing
End Sub
PS. I tested my previous macro on a single footnote made of several paragraphs, but not
on several footnotes on the same page. This is the reason for my misunderstanding.
If you want to include the main text in the macro, add this just after ScreenUpdating = False line:
With ActiveDocument.range.Find
.ClearFormatting
.Replacement.ClearFormatting
.text = "^w^p"
.Replacement.text = "^p"
.MatchWildcards = False
.Execute Replace:=wdReplaceAll
End With
Reply With Quote
  #5  
Old 10-07-2023, 11:21 PM
RobiNew RobiNew is offline Remove spaces before each paragraph mark in text and footnotes Windows 10 Remove spaces before each paragraph mark in text and footnotes Office 2016
Competent Performer
Remove spaces before each paragraph mark in text and footnotes
 
Join Date: Sep 2023
Posts: 208
RobiNew is on a distinguished road
Default

Hi Vivka! Sorry, but your code does not work on automatic footnotes. The reason for this is that it is again based on a replacement action which is not allowed (even if ^p is absent in the .Replacement.text). If it were possible to replace footnote ending paragraphs, then any user could destroy the footnotes by mistake. If you try a Find&Replace action of the type ^p ---> "" (or ---> ^l) on any text with multiple paragraphs you will get a single paragraph. If you could do that in the automatic footnotes area you would get a single footnote out of a whole series of footnotes.
Reply With Quote
  #6  
Old 10-16-2023, 01:51 AM
RobiNew RobiNew is offline Remove spaces before each paragraph mark in text and footnotes Windows 10 Remove spaces before each paragraph mark in text and footnotes Office 2016
Competent Performer
Remove spaces before each paragraph mark in text and footnotes
 
Join Date: Sep 2023
Posts: 208
RobiNew is on a distinguished road
Default

Hi Vivka! The code here below produces an error. Can you help? Thanks!



Code:
Sub EliminaSpazio()
'Text and Footnotes: Removes space before paragraph mark
'Qui per poi eliminare tutti i paragrafi vuoti.
Dim aRng As Range
Dim iType As Integer
Dim Para As Paragraph
    For iType = 1 To 2
Set aRng = ActiveDocument.StoryRanges(iType)
For Each Para In aRng.Paragraphs
If Para.Range.Characters.Last.Previous = " " Then 'ERROR
Para.Range.Characters.Last.Previous.Delete
End If
Next Para
    Next iType
Set aRng = Nothing
End Sub
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove spaces before each paragraph mark in text and footnotes How to remove gap between text and footnotes on Mac? gemmajackson7 Word 1 05-16-2021 07:26 AM
Remove spaces before each paragraph mark in text and footnotes How to Remove trailing spaces AND line breaks in a block of text JulianS96 Word 4 02-04-2020 04:20 AM
Remove spaces before each paragraph mark in text and footnotes Remove Paragraph / Spaces sharina1985 Mail Merge 1 10-05-2019 03:52 AM
big spaces appearing automatically in certain parts of the text - how to remove them pratodifuoco Word 2 05-26-2017 12:55 PM
editing text and remove spaces romanticbiro Word VBA 5 07-04-2014 07:42 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:43 AM.


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