Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
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: 183
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, 11 views)
Reply With Quote
  #17  
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
Competent Performer
 
Join Date: Jul 2023
Posts: 227
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
  #18  
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: 183
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
  #19  
Old 10-08-2023, 12:57 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
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Hi, RobiNew! But the code works properly on all the footnotes in your file! Unfortunately, I can't attach photos here.
Reply With Quote
  #20  
Old 10-08-2023, 01:12 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: 183
RobiNew is on a distinguished road
Default

But it doesn't work here in my file. I also tried the step by step activation but nothing changes. Sorry!
Reply With Quote
  #21  
Old 10-08-2023, 03:20 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
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

It's so strange! I'm empty for ideas! If the same file works on one system and doesn't work on the other, obviously the reason is the system and obviously I can't find a solution. It's a pity! I wanted and still want to help you. Maybe someone else will help us.
Reply With Quote
  #22  
Old 10-08-2023, 03:42 AM
Guessed's Avatar
Guessed Guessed 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
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

Try this version then
Code:
Sub CleanParas()
  Dim oRng As Range, iType As Integer
  For iType = 1 To 2
    Set oRng = ActiveDocument.StoryRanges(iType)
    With oRng.Find
      .ClearFormatting
      .Text = "^w^p"
      While .Execute
        'oRng.Select
        oRng.MoveEnd Unit:=wdCharacter, Count:=-1
        'oRng.Select
        oRng.Text = ""
      Wend
    End With
  Next iType
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia

Last edited by Guessed; 10-08-2023 at 02:43 PM.
Reply With Quote
  #23  
Old 10-08-2023, 03:43 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
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Thnk you, Andrew! Your code works charmingly! But I wanted to offer something in line of Find-Replace (out of pure research interest). And I managed to get the expected result (at least on my system):

Before hosted at ImgBB — ImgBB
After hosted at ImgBB — ImgBB


However, to be honest, I don't see a practical value of deleting final spaces in footnotes.
Reply With Quote
  #24  
Old 10-08-2023, 07:12 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: 183
RobiNew is on a distinguished road
Default

High, Guessed! To me your code is an interesting variant when ^p in the footnotes is preceded by multiple spaces. Thanks!
High, Vivka! The mystery of the two different systems remains. Under certain circumstances it is useful to have a code for deleting final spaces in footnotes: I use the code in post 14, modified according to your suggestions in post 15. Thanks a lot for your time and patience!
Reply With Quote
  #25  
Old 10-08-2023, 10:36 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
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

RobiNew, thank you for your kind words! It's a pity I couldn't help you (and satisfy my curiosity).
Reply With Quote
  #26  
Old 10-08-2023, 10:24 PM
miumiu4546 miumiu4546 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 2019
Novice
 
Join Date: Oct 2023
Posts: 5
miumiu4546 is on a distinguished road
Default

Finding a solution proves to be challenging; I hope you can tackle it.
Reply With Quote
  #27  
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: 183
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
  #28  
Old 10-16-2023, 02:48 AM
Guessed's Avatar
Guessed Guessed 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
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

I presume that in paragraphs that contain only the paragraph mark, there is no previous character in front of the last (only) character.

So what do you think you might do to avoid the error?
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #29  
Old 10-16-2023, 03:53 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: 183
RobiNew is on a distinguished road
Default

Thanks Guessed! You've Guessed right. But this modification doesn't work:


Code:
If Para.Range.Characters.Last.Previous = " " _
And Para.Range.Characters.Last.Previous <> Chr(13) Then
Para.Range.Characters.Last.Previous.Delete
Reply With Quote
  #30  
Old 10-16-2023, 04:55 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
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Hi, guys! I don't think that absence of space before Chr(13) is the reason for the error (what kind of error?). Presence of space is just a condition. If it is not positive, the code goes on to the next paragraph. I've checked it on different paragraphs. And again, it's curious and challenging, but the code from post 27 works smoothly on the Test_Test file sent by RobiNew previously!

Note that the code removes only 1 space at one run. To remove all spaces, Do...Loop is needed.
Reply With Quote
Reply



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 02:09 PM.


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