Results 1 to 3 of 3
  1. #1
    century
    Guest

    Merging documents (Word/97)

    Hi

    I am trying to merge documents together by VBA. The problem is I need to identify specific pages from the merge from document and merge them into the destination document. Ideally I need to select whole pages and then merge them according to the data held on the page. So for example if the first word on a page contains the data I'm looking for I would want to select that page and "copy and paste" it to the destination document.

    Kind Regards

    Andy

  2. #2
    4 Star Lounger
    Join Date
    Dec 2000
    Location
    Quakertown, PA, Pennsylvania, USA
    Posts
    517
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Merging documents (Word/97)

    I hear of people doing this type of thing a lot. Why aren't you using an Autotext entry instead?

    Instead of copy/paste, use Insert-File.

    Hope this helps, sorry if it doesn't!

  3. #3
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Merging documents (Word/97)

    Andy,

    A little-known but very powerful feature of the .InsertFile method in VBA, is that it allows you to specify a bookmarked range for insertion. This permits you to use a Word file (or a .txt file) as a datasource. The basic syntax looks like this:

    <pre>Public Sub InsertBookmarkedText()
    Selection.InsertFile _
    FileName:="FullPath and Name of document.doc", _
    Range:="BookmarkName"
    End Sub
    </pre>

    To take advantage of this feature in the current instance:
    If the source document is fairly static, you could try bookmarking each page. Then it would be pretty simple to use the above to pull in the bookmarked page only.
    If the source document is dynamic, then you can still do it but it's a bit more trouble. The steps involved might be along the lines of:
    Do a find to locate the first word that you're looking for.
    If found, select that entire page.
    Add a bookmark to the selected page.
    Then use the above method to pull in the bookmarked text.
    Post back if you need a more detailed code example.

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •