Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2007

Tip: Looking for answers? Try searching our database.

Inserting one document into another

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
morten.slogedal@ventelo.no - 26 Mar 2007 11:06 GMT
Hi

I need help with getting some functions to a VBA scrit for Word.

I want to use a dialog box to choose an option, and when that option i
selected, I want to insert an external document into the current
document.

What function(s) do I use for this?

- Morten
Doug Robbins - Word MVP - 26 Mar 2007 11:44 GMT
Better to give a bit more detailed information.  Is it always going to be
the same document, or will the user be selecting the document in some way in
the dialog box?  Where abouts in the document is the other document to be
inserted?

To answer the question as you have asked it, you would use the FormattedText
property of the Range of the document that you want to insert.

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Hi
>
[quoted text clipped - 7 lines]
>
> - Morten
morten.slogedal@ventelo.no - 26 Mar 2007 12:41 GMT
Thank you for fast response!

More detailed information;

- I have a .DOT template that holds the VBA script and some default
text.
- Within the text I have a bookmark, and on this bookmark I want to
insert an external .doc file with some other text.
- These .doc files varies as you choose an "option" from the UserForm.
- I also want to include a file on a "New page" (page 2) of the
current document from an external .doc file.

Code:
----------------
If Popup.optEierskifte.Value = True Then
   ActiveDocument.Bookmarks("bkBrevinnhold").Range.Text = "test"
End If
----------------

So, basicly I need:

1. The function to include all contents of the external .doc file
instead of "test" within the template bookmark.
2. The function to insert an external .doc file to the end of the
template, as a new page within the same template.

An example would be nice :D

Thanks in advance!
Doug Robbins - Word MVP - 26 Mar 2007 14:04 GMT
Dim docrange as Range
Dim Target as Document, Source as Document
Set Target = ActiveDocument
Set Source = Documents.Open("Drive:\Path\Filename")
Set docrange=Source.Range
Target.Bookmarks("bkBrevinnhold").Range.Text = docrange.FormattedText
Source.Close wdDoNotSaveChanges

For the other:

With Target.Range
   .Collapse wdCollapseEnd
   .InsertBreak Type" = wdPageBreak
   .Text = docrange.FormattedTExt
Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Thank you for fast response!
>
[quoted text clipped - 25 lines]
>
> Thanks in advance!
morten.slogedal@ventelo.no - 26 Mar 2007 15:21 GMT
Sweet!

Very nice, that helped alot. Now it inserts correctly in the first
part.

But I would like to keep the formatting on the inserted file, as I
have tables and different fonts/setups on the inserted document.
As it is now It inserts as clean-text as a "copy&paste" filtered thru
notepad, hehe..

So inserting all this with the parameter to keep formattings and
tables etc as all I need now =)

If you would know how to do this, I would appriciate a response to
this too.

Thank you anyway for your help, saved me alot of time today! /bow
Doug Robbins - Word MVP - 26 Mar 2007 17:59 GMT
Try

With Target.Range
   .Collapse wdCollapseEnd
   .InsertFile Filename: = "Drive:\Path\Filename"
End With

I am never sure to which range the .FormattedText attribute should be
applied.  It won't hurt to apply it to both.

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Dim docrange as Range
> Dim Target as Document, Source as Document
[quoted text clipped - 39 lines]
>>
>> Thanks in advance!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.