'''' This code is part of Document Solutions for Word demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.LinqImportsGrapeCity.Documents.Word '' This sample shows how to copy or move ranges within a document,'' or between documents, using the RangeBase.CopyTo()/MoveTo() methods.'''' The original SampleParagraphs.docx used in this sample can be'' seen by running the SampleParagraphs sample.PublicClassRangeCopyMovePublicFunctionCreateDocx() AsGcWordDocumentConstp1start = "This is the first paragraph of the original document"Constp2start = "This is the second paragraph of the original document"Constp3start = "This is the third paragraph of the original document"Constp4start = "This is the fourth paragraph of the original document" '' Load the sample DOCX file (see SampleParagraphs) into a GcWordDocument instance:Dim srcDoc = NewGcWordDocument() srcDoc.Load(Path.Combine("Resources", "WordDocs", "SampleParagraphs.docx")) '' Get the range of paragraphs to copy:Dim srcRng = srcDoc.Body.GetPersistentRange(srcDoc.Body.Paragraphs(2), srcDoc.Body.Paragraphs.Last) '' We use another document here to demonstrate that CopyTo()/MoveTo() methods'' can be used to copy/move content between documents:Dim doc = NewGcWordDocument() srcRng.CopyTo(doc.Body, InsertLocation.Start) '' Find individual paragraphs inside the new document to manipulate:Dim p1 AsParagraph = Nothing, p2 AsParagraph = Nothing, p3 AsParagraph = Nothing, p4 AsParagraph = NothingForEach p In doc.Body.ParagraphsDim t = p.GetRange().TextIf t.StartsWith(p1start) Then p1 = pElseIf t.StartsWith(p2start) Then p2 = pElseIf t.StartsWith(p3start) Then p3 = pElseIf t.StartsWith(p4start) Then p4 = pEndIfNextIf p1 IsNothingOrElse p2 IsNothingOrElse p3 IsNothingOrElse p4 IsNothingThenThrowNew Exception("Unexpected: could not find paragraphs.")EndIf '' Move first paragraph to the end of the document with default formatting option'' (preserve formatting): p1.GetRange().MoveTo(doc.Body, InsertLocation.End) '' Move second paragraph to the end of the document, clearing formatting: p2.GetRange().MoveTo(doc.Body, InsertLocation.End, FormattingCopyStrategy.Clear) '' Copy third paragraph to the end of the document, clearing formatting: p3.GetRange().CopyTo(doc.Body, InsertLocation.End, FormattingCopyStrategy.Clear) '' Add a note at the end of the document: doc.Body.Sections.Last.GetRange().Paragraphs.Add($"Created by DsWord on {Util.TimeNow():R}.") '' Done:Return docEndFunctionEndClass