Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-02-2023, 10:03 AM
RobiNew RobiNew is offline Add a spacing character before a hard return Windows 10 Add a spacing character before a hard return Office 2016
Competent Performer
Add a spacing character before a hard return
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default Add a spacing character before a hard return


I need to insert a spacing character " " before a hard return. I've tried the code here below, but it produces an error. Any idea? Thanks!

Code:
Sub Problem()
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 11-02-2023, 11:28 AM
vivka vivka is offline Add a spacing character before a hard return Windows 7 64bit Add a spacing character before a hard return Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

RobiNew, your code works smoothly on my documents.
Reply With Quote
  #3  
Old 11-03-2023, 12:36 AM
RobiNew RobiNew is offline Add a spacing character before a hard return Windows 10 Add a spacing character before a hard return Office 2016
Competent Performer
Add a spacing character before a hard return
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default

Hi Vivka! It works in the text sector, but in the footnote sector it gives this error: "Runtime Error.
Invalid operation for the end of a line". Thanks!
Reply With Quote
  #4  
Old 11-03-2023, 03:32 AM
vivka vivka is offline Add a spacing character before a hard return Windows 7 64bit Add a spacing character before a hard return Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

It's amazing, because I don't have this error neither on the main text, nor on the footnotes. I will try to experiment.
Reply With Quote
  #5  
Old 11-03-2023, 05:31 AM
vivka vivka is offline Add a spacing character before a hard return Windows 7 64bit Add a spacing character before a hard return Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

RobiNew, I can't detect any problem! May I see your file?
Reply With Quote
  #6  
Old 11-03-2023, 05:44 AM
vivka vivka is offline Add a spacing character before a hard return Windows 7 64bit Add a spacing character before a hard return Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

RobiNew, please, see the attached pics (Before and After running your code):
Attached Images
File Type: png Before.png (3.6 KB, 10 views)
File Type: png After.png (3.6 KB, 10 views)
Reply With Quote
  #7  
Old 11-03-2023, 10:45 AM
RobiNew RobiNew is offline Add a spacing character before a hard return Windows 10 Add a spacing character before a hard return Office 2016
Competent Performer
Add a spacing character before a hard return
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default

Hi, Vivka! Of course you are right. The code in question gives an error only in one specific (very large) doc, which I cannot upload because it contains sensitive material. Sorry to have troubled you with this problem. Thanks! À la prochaine!
Reply With Quote
  #8  
Old 11-03-2023, 11:44 AM
vivka vivka is offline Add a spacing character before a hard return Windows 7 64bit Add a spacing character before a hard return Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Bye until next time!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace a hard return with a dash in the text of a footnote RobiNew Word VBA 3 11-02-2023 09:22 AM
Macro for Find/replace to remove space before Hard Return AlfredStreich Word VBA 4 01-23-2020 03:59 PM
Add a spacing character before a hard return Find / Replace hard Carriage Return with Line break. GreenBoy Word 2 03-11-2018 02:32 AM
Hard return renders upper case clafond Word 2 01-07-2013 12:26 PM
Hard page return? markg2 Outlook 0 09-11-2012 08:49 AM

Other Forums: Access Forums

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