PDA

View Full Version : Inserting parts of other word-document



advin
01-10-2011, 04:12 AM
Hallo,

Is there a way to insert only sepecific sections of another document into my document via VBA, rather than using Selection.InsertFile to insert the whole document?

Additional Info:
currently we use Selection.insertFile to insert existing word-documents containing descriptions into our doc.

There are lots of descriptions(>500).However, the descriptions are quite samll (<500 characters) and as this needs to be possible in offline-mode we cannot host them on the server and need to copy all the files. This slows down performance as all docs have to be synchronized.

any hint is highly appreciated.

macropod
01-10-2011, 07:59 AM
Hi Advin,

InsertFile works with Range objects, as well as with Selections. It is usually better to work with Ranges. Whichever way you go, though, processing 500+ description files could be a lengthy process. Storing them as plain text files (if that's suitable) would enable faster processing.

As for processing individual Sections, that's certainly possible, but that would require the Section in the source document to be bookmarked. The InsertFile method takes the following parameters:
.InsertFile(FileName, Range, ConfirmConversions, Link, Attachment)
See Word's vba Help file for details.

Note too that, if you use the 'Link' parameter, that will enable your target document to maintain active links to all the source documents so that, instead of having to update all the descriptions, you can update only the ones that have changed - all without having to open the source files.

fumei
01-10-2011, 09:47 AM
Just trying to clarify. You have 500+ separate WORD files that are being brought in via InsertFile?

Ai caramba!

Is there any way you can change that situation (if it is indeed that way)? As Paul mentions, even if they were text files (rathe rthan Word docs) would make a big difference.

Or, one Word document with each of the descriptions as bookmarked text. That woul dmake it much easier, and faster.

advin
01-11-2011, 09:23 AM
Hallo,

thanks for the hints. However, plain text-files, as well as a db-datasource is not suitable as the descriptions contain (not many but unfortunately necessary) formated characters, in most cases bold parts as well as lists.

BUT, and this is where i hope to get another hint: I can choose the format the document that contains all descriptions needs to look like. (This means i can decide whether each description should be listed in a sepearate table row or bookmarked. I guess thats helpful, isnt it?

When inseting a range from another document via insertfile, is the other document opened in the background? How does this basically work?

Greets, Michael

macropod
01-11-2011, 01:45 PM
Hi Michael,

So what process decides the bolding in the source files? If there's some vba code behind that, the same logic could quite possibly be used to correctly format data imported from plain text files.

I don't follow what you mean by:

This means i can decide whether each description should be listed in a sepearate table row or bookmarked
Presumably, the InsertFile method opens the source file in the background (certainly not in the foreground), to read the data. However, even if you have all the descriptions in the same file, each InsertFile operation would require making a separate call to the source file.

advin
01-12-2011, 01:20 AM
Hi,

the bolding is defined by some users that create those descriptions, so no vb-code behind that.

I meant that I can decide how the document, that should contain all descriptions needs to be designed.
So if it is possible to Insert bookmarked ranges with InsertFile-Method, i think we can create a Description file containing all descriptions where each of them is bookmarked and then insert the section i need?

I will give it a try and let you know!

@fumai: Not all of the descriptions are loaded in each document, but could be +100 in some cases.

Tinbendr
01-12-2011, 06:00 AM
I think we could help you better if you mock us up a few files as an example.

Be sure to explain before and after in the source document.

Just zip them up and u/l them using Manage Attachments at the bottom of the post.

David

fumei
01-12-2011, 11:18 AM
Perhaps try using an INCLUDETEXT field. Format is covered.

{ INCLUDETEXT "c:\\Whatever\\DescriptionSource.doc" D1 \* MERGEFORMAT }

Note:
If you enter the path/filename in the Insert>Field dialog, enter it with single slashes. Word changes it to double slashes. If you edit it, use double slashes.

The above field inserts without opening the file, the bookmarked contents named D1.

This is description #1
Blah blah blah

Both lines are in the bookmark D1.