#16
|
|||
|
|||
Hi Vivka! Thank you for your patience. I'm attaching a test file with footnotes. |
#17
|
|||
|
|||
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 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 |
#18
|
|||
|
|||
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.
|
#19
|
|||
|
|||
Hi, RobiNew! But the code works properly on all the footnotes in your file! Unfortunately, I can't attach photos here.
|
#20
|
|||
|
|||
But it doesn't work here in my file. I also tried the step by step activation but nothing changes. Sorry!
|
#21
|
|||
|
|||
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.
|
#22
|
||||
|
||||
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. |
#23
|
|||
|
|||
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. |
#24
|
|||
|
|||
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! |
#25
|
|||
|
|||
RobiNew, thank you for your kind words! It's a pity I couldn't help you (and satisfy my curiosity).
|
#26
|
|||
|
|||
Finding a solution proves to be challenging; I hope you can tackle it.
|
#27
|
|||
|
|||
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 |
#28
|
||||
|
||||
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 |
#29
|
|||
|
|||
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 |
#30
|
|||
|
|||
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. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to remove gap between text and footnotes on Mac? | gemmajackson7 | Word | 1 | 05-16-2021 07:26 AM |
How to Remove trailing spaces AND line breaks in a block of text | JulianS96 | Word | 4 | 02-04-2020 04:20 AM |
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 |