![]() |
|
|||||||
|
|
|
Thread Tools | Display Modes |
|
|
|
#1
|
||||
|
||||
|
The following macro will find the next paragraph that begins with the selected text and will insert the paragraph that contains the selected text before it. It assumes that at least two words are selected. You can change that as appropriate. http://www.gmayor.com/installing_macro.htm
Code:
Sub Macro1()
'Graham Mayor - http://www.gmayor.com - Last updated - 28 Oct 2018
Dim oRng As Range, oSel As Range
Set oSel = Selection.Range
If oSel.Words.Count > 2 Then
Set oRng = ActiveDocument.Range
oRng.Start = oSel.Paragraphs(1).Range.End
With oRng.Find
Do While .Execute(oSel)
If oRng.Start = oRng.Paragraphs(1).Range.Start Then
oRng.Collapse 1
oRng.FormattedText = oSel.Paragraphs(1).Range.FormattedText
oSel.Paragraphs(1).Range.Delete
Exit Do
End If
oRng.Collapse 0
Loop
End With
End If
lbl_Exit:
Set oRng = Nothing
Set oSel = Nothing
Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#2
|
|||
|
|||
|
WOW !!!!
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() That's great, thanks : it's 99% what I was dreaming of ! The last thing is : I need the macro to work on a chain, no matter whether it is 3 characters or a whole sentence (typically I would select 4 or 5 characters). Could you help me do this, please ? THANKS !!!!!!! |
|
#3
|
|||
|
|||
|
OK, I've just changed
Code:
If oSel.Words.Count > 2 Then Code:
If oSel.Words.Count > 1 Then Am I right ? |
|
#4
|
|||
|
|||
|
After further testing, this small change is not enough to make the macro work ie on a 3 characters chain...
|
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Document starts to red line spaces and formatting appears on right side
|
Richtriebe | Word | 2 | 03-23-2017 11:53 AM |
| Bold each line of text that starts with a recurring symbol | qubie | Word | 6 | 08-26-2016 07:10 AM |
| Lock line so text does not move to next line | saundrals | Word | 2 | 06-19-2014 03:59 PM |
Identify certain text and move all phrases containing it down a line
|
Chayes | Word VBA | 2 | 11-26-2013 01:16 PM |
How to give line numbering to only selected text?
|
garlapati | Word | 5 | 04-04-2011 02:05 PM |