PDA

View Full Version : [SOLVED:] extract text from a documents bookmark and insert it in another document



wolle271
08-04-2014, 06:28 AM
hey,

im trying to extract text from a word document at a bookmark and insert that text into another word document at a specific bookmark.
so, basically i have a word template(lets call it "template.dot") thats divided by bookmarks. now i want to create a new document(new.doc) using the template(template.doc) and then insert text from another file(text.doc) at a bookmark.

in pseudocode it would be something like this:

make new document("new.doc") using template.dot
go to bookmark "inserthere" in new.doc
add the text from "text.doc" at bookmark "example"

i would be really happy if you guys could help me.
thx in advance

macropod
08-04-2014, 08:56 PM
Basically:

Sub Demo()
Dim DocSrc As Document, DocTgt As Document
Set DocTgt = Documents.Add(Template.dot)
Set DocSrc = Documents.Open(Text.doc, AddTorecentFiles:=False, Visible:=False)
DocTgt.Bookmarks("TgtBookmark").Range.FormattedText = DocSrc.Bookmarks("SrcBookmark").Range.FormattedText
DocSrc.Close , False
Set DocTgt = Nothing: Set DocSrc = Nothing
End Sub