![]() |
|
#2
|
||||
|
||||
|
The following will address the text paragraphs but not tables. Basically it creates two content controls into which each paragraph is copied. The red paragraphs are not editable.
Code:
Sub Macro1()
'Graham Mayor - https://www.gmayor.com - Last updated - 05 Mar 2020
Dim oSource As Document, oTarget As Document
Dim oRng As Range
Dim oPara As Paragraph
Dim oCC1 As ContentControl, oCC2 As ContentControl
Set oSource = ActiveDocument
oSource.Save
If oSource.Path = "" Then GoTo lbl_Exit
Set oTarget = Documents.Add(oSource.FullName)
oTarget.Range.Text = vbCr
For Each oPara In oSource.Paragraphs
If oPara.Range.Information(wdWithInTable) = False And Len(oPara.Range) > 1 Then
Set oRng = oTarget.Range
oRng.Collapse 0
Set oCC1 = oTarget.ContentControls.Add(wdContentControlRichText, oRng)
oCC1.Range.Text = oPara.Range.Text
oCC1.Range.Font.ColorIndex = wdRed
oCC1.LockContentControl = True
oCC1.LockContents = True
Set oRng = oTarget.Range
oRng.Collapse 0
Set oCC2 = oTarget.ContentControls.Add(wdContentControlRichText, oRng)
oCC2.Range.Text = oPara.Range.Text
oCC2.Range.Font.ColorIndex = wdBlue
oCC2.LockContentControl = True
End If
Next oPara
oTarget.Paragraphs(1).Range.Delete
lbl_Exit:
Set oSource = Nothing
Set oTarget = Nothing
Set oRng = Nothing
Set oPara = 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 |
| Tags |
| 4605, copy/paste paragraph, tables |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
delete 1 or 2 adjacent duplicate paragraphs, macro
|
moorea21 | Word | 4 | 11-01-2018 12:53 PM |
How to find duplicate phrases/paragraphs in a long document
|
iamgator | Word VBA | 5 | 12-27-2016 01:34 AM |
Using VB.Net 2010 I cannot duplicate tables in the correct place
|
AaaTeX | Word Tables | 3 | 08-03-2014 07:00 PM |
| Show & hide paragraphs, parts of tables, etc | Preloader | Word | 2 | 10-19-2013 02:37 PM |
add the functionality to show & hide paragraphs, parts of tables, etc
|
pgwolfe | Word | 3 | 09-24-2013 07:58 PM |