Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-26-2023, 12:45 PM
Harvi007 Harvi007 is offline VBA to add Shift+Enter at the beginning of each line Windows 11 VBA to add Shift+Enter at the beginning of each line Office 2019
Novice
VBA to add Shift+Enter at the beginning of each line
 
Join Date: Aug 2022
Posts: 11
Harvi007 is on a distinguished road
Question VBA to add Shift+Enter at the beginning of each line

Hi,



I was looking for some help with a vba macro please.

I need to find an automated way to add Shift+Enter at the beginning of each line in a document.

I found some code that adds char160 at the end of a line that has a space on the end, but this is not consistent and also misses lines that have a comma on the end.

The reason for the Shift+Enter is to allow the text to then be justified correctly.

Please, any help with this would be greatly appreciated.

Thank you
Reply With Quote
  #2  
Old 03-27-2023, 03:21 AM
Harvi007 Harvi007 is offline VBA to add Shift+Enter at the beginning of each line Windows 11 VBA to add Shift+Enter at the beginning of each line Office 2019
Novice
VBA to add Shift+Enter at the beginning of each line
 
Join Date: Aug 2022
Posts: 11
Harvi007 is on a distinguished road
Lightbulb Half working...

Hi,

I've had a look around and a bit of a play.

The following code seems to do what I'm looking for, but can't handle 'Page Break' and thus keeps adding 'Enter' until I end the macro.


Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Do
Selection.EndKey Unit:=wdLine
If Selection.End >= ActiveDocument.Content.End - 1 Then
Exit Do
End If
If Asc(Selection) <> 13 Then
Selection.InsertParagraphAfter
End If
Selection.MoveDown Unit:=wdLine
Loop
Application.ScreenUpdating = True

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find

.Text = "^p"
.Replacement.Text = "^l"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll

End With

Please if anyone can help me get past the 'Page Break', that will help me complete my goal.

Thanks in advance,
Reply With Quote
  #3  
Old 03-27-2023, 09:07 AM
Harvi007 Harvi007 is offline VBA to add Shift+Enter at the beginning of each line Windows 11 VBA to add Shift+Enter at the beginning of each line Office 2019
Novice
VBA to add Shift+Enter at the beginning of each line
 
Join Date: Aug 2022
Posts: 11
Harvi007 is on a distinguished road
Unhappy back to square one

Scratch my last post, the results are very inconsistent, it's doing some pages and leaving others.

Please help
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to add Shift+Enter at the beginning of each line MS Word Horizontal Line Disappears after pressing Enter from end of line MikeWhite Word 5 01-20-2017 03:39 PM
VBA to add Shift+Enter at the beginning of each line Can't insert space at the beginning of a line in Word p89.schneider Word 6 03-24-2016 11:38 PM
VBA to add Shift+Enter at the beginning of each line What about this dotted line at the beginning of a task? patrickd123 Project 3 04-24-2015 01:27 PM
Dash in the beginning of a new line Wakinyan Word 0 07-11-2010 07:10 AM
VBA to add Shift+Enter at the beginning of each line Add text to the beginning/ending of each line in word ballmoney Word 1 01-17-2010 02:19 AM

Other Forums: Access Forums

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