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

Re: Append a template several times to a document by Word

Word
Thu Dec 11 16:15:10 CST 2003

G'day ledde@home.se (Henrik),

Dim BM as Bookmark

For each BM in oTemplate.Bookmarks
...
next

ledde@home.se (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.

Re: Append a template several times to a document by ledde

ledde
Fri Dec 12 01:44:27 CST 2003

Word Heretic <myname@wordheretic.com> wrote in message news:<e2rhtvgnaieaub0kaiefoke7fg9bs7iq1k@4ax.com>...
> G'day ledde@home.se (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

Re: Append a template several times to a document by Word

Word
Fri Dec 12 15:34:13 CST 2003

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



ledde@home.se (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.