Append a template several times to a document

H

Henrik

Hi I'm new to Word Automation and would need some help

I have a template with bookmarks I would like to append several times
to my main document.

Here is what i try to do, question is in "Do... Loop" statement.

Dim oWordApp As New Word.ApplicationClass
Dim oMainDoc As Word.DocumentClass
Dim oTemplate As Word.DocumentClass

oMainDoc = oWordApp.Documents.Add()
oTemplate = oWordApp.Documents.Add("c:\\test\\template.dot")

oMainDoc.Activate()

Do
' First I update the bookmarks on my oTemplate
' Then I want to append it's complete content to oMainDoc
' But how do I do that???

' I know I could save oTemplate to a temp document
' and then use
' oWordApp.Selection.InsertFile("temp_document_fullpath")
' But think there must be a better way of doing it

' If I only wanted the text in the template I could
' use
' oWordApp.Selection.TypeText(oTemplate.Content.Text())
' But I want it complete with all styles, tables and stuff

Loop While foo = 1


Thanks in advance,

Henrik
 
W

Word Heretic

G'day (e-mail address removed) (Henrik),

Dim BM as Bookmark

For each BM in oTemplate.Bookmarks
....
next

(e-mail address removed) (Henrik) was spinning this yarn:
Hi I'm new to Word Automation and would need some help

I have a template with bookmarks I would like to append several times
to my main document.

Here is what i try to do, question is in "Do... Loop" statement.

Dim oWordApp As New Word.ApplicationClass
Dim oMainDoc As Word.DocumentClass
Dim oTemplate As Word.DocumentClass

oMainDoc = oWordApp.Documents.Add()
oTemplate = oWordApp.Documents.Add("c:\\test\\template.dot")

oMainDoc.Activate()

Do
' First I update the bookmarks on my oTemplate
' Then I want to append it's complete content to oMainDoc
' But how do I do that???

' I know I could save oTemplate to a temp document
' and then use
' oWordApp.Selection.InsertFile("temp_document_fullpath")
' But think there must be a better way of doing it

' If I only wanted the text in the template I could
' use
' oWordApp.Selection.TypeText(oTemplate.Content.Text())
' But I want it complete with all styles, tables and stuff

Loop While foo = 1


Thanks in advance,

Henrik

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
wordheretic.com

If my answers r 2 terse, ask again or hassle an MVP,
at least they get recognition for it then.
Lengthy replies offlist require payment.
 
H

Henrik

Word Heretic said:
G'day (e-mail address removed) (Henrik),

Dim BM as Bookmark

For each BM in oTemplate.Bookmarks
...
next


Hi Steve!

Thanks a lot, but the part I had problem with
was appending/insert the template document to the
main document. Sorry for being unclear.

I found a solution using copy and paste,
but I'm still not sure it's the best way

The append/part in the loop

oTemplate.Content.Copy
oMainDoc.Selection.Paste

Don't think it's a smart way when you have to do
over 1000's of copy/paste

How do I delete "my part" of the clipboard afterwards?


Regards,

Henrik
 
W

Word Heretic

G'day Henrik,

FWIW I use this sort of method (copy/paste) all the time. It works
very well and once you get used to Word it has a definite place within
the VBA & DOM paradigms.

The VBA Developer's Handbook (Sybex, Ken Getz et al) has some nice
stuff for dealing with the system clipboard. There may even be some
pointers over at www.mvps.org/word/FAQs/index.htm



(e-mail address removed) (Henrik) was spinning this yarn:

Hi Steve!

Thanks a lot, but the part I had problem with
was appending/insert the template document to the
main document. Sorry for being unclear.

I found a solution using copy and paste,
but I'm still not sure it's the best way

The append/part in the loop

oTemplate.Content.Copy
oMainDoc.Selection.Paste

Don't think it's a smart way when you have to do
over 1000's of copy/paste

How do I delete "my part" of the clipboard afterwards?


Regards,

Henrik

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
wordheretic.com

If my answers r 2 terse, ask again or hassle an MVP,
at least they get recognition for it then.
Lengthy replies offlist require payment.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top