Sarahmueller
New Member
- Joined
- May 17, 2020
- Messages
- 24
- Office Version
- 365
- 2016
- Platform
- Windows
Hello,
i hope you all are healthy!
I want to insert the text written between two bookmarks ("Beginning_old") and ("End_old") of an baseline word document, into a new word document.
In the new word document, the text should be inserted between a bookmark called "Beggining_newdoc" and a bookmark called "End_newdoc". Afterwards, the new document should save and close.
I have come up with the following code:
Nevertheless, this code only replaces the bookmarks in the new document with the ones of the old document.
Do you have an idea how to modify the macro, so that the text between the old bookmarks ["Beginning_old" and "End_old"] is inserted between the bookmarks ["Beggining_newdoc" and "End_newdoc"]
of the new word document?
Thank you in advance and best regards,
Sarah
i hope you all are healthy!
I want to insert the text written between two bookmarks ("Beginning_old") and ("End_old") of an baseline word document, into a new word document.
In the new word document, the text should be inserted between a bookmark called "Beggining_newdoc" and a bookmark called "End_newdoc". Afterwards, the new document should save and close.
I have come up with the following code:
VBA Code:
Sub Insertbetweenbookmarks()
Dim oTarDoc As Document, oSourceDoc As Document
Dim oRng As Word.Range
Set oSourceDoc = ActiveDocument
Set oTarDoc = Documents.Open("C:\path of new document")
With oTarDoc
Set oRng = .Bookmarks("Beggining_newdoc").Range
oRng.Text = oSourceDoc.Bookmarks("Beginning_old").Range.Text
.Bookmarks.Add "Beggining_newdoc", oRng
Set oRng = .Bookmarks("End_newdoc").Range
oRng.Text = oSourceDoc.Bookmarks("End_old").Range.Text
.Bookmarks.Add "End_newdoc", oRng
End With
lbl_Exit:
Exit Sub
End Sub
Nevertheless, this code only replaces the bookmarks in the new document with the ones of the old document.
Do you have an idea how to modify the macro, so that the text between the old bookmarks ["Beginning_old" and "End_old"] is inserted between the bookmarks ["Beggining_newdoc" and "End_newdoc"]
of the new word document?
Thank you in advance and best regards,
Sarah