Solved

Add Documents to a word document

Posted on 2014-11-17
4
205 Views
Last Modified: 2014-11-18
Experts, I am working on an application for our sales staff to build a quote. A quote can consist of one page or ten pages. Each of the pages are Word Documents that I have stored for use as templates. What I want to do is based on the options the user has chosen, create an instance of the required templates and then build a new word document with those objects. Could someone show me an example of doing this if for instance I create a new object like this:

Dim oWord as new Word.Application
Dim oDoc  as oWord.Documents.Open(myPath)

How could I then add other objects to this document?
0
Comment
Question by:Basicfarmer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 40448393
That is one way of doing it. Another is to start of with all possible pages and delete those not needed.

Actually, I think the way that MS would expect to be used is to store each page as a Building block in a Template.

However, you can add the text of one document at the end of the open one with code like this:
oDoc.Bookmarks("\EndOfDoc").Range.InsertFile "C:\MyFolder\MyDoc1.docx"

Open in new window

0
 

Author Comment

by:Basicfarmer
ID: 40448404
Graham, would you expand on what you mentioned previously a little bit. Im not real clear on what you are saying.
"Actually, I think the way that MS would expect to be used is to store each page as a Building block in a Template"
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 40448512
If you are familiar with pre-2007 Word, it is best understood as an extension of Autotext.

There is a button labelled 'Quick Parts' which can be accessed via the Insert tab.

If you choose 'Building Blocks Organizer...' you will see a list of formatted text that has been stored in the default 'Building Blocks'  template. If you choose 'Insert' on the dialogue, the selected item will be inserted into the current document.

If you already have some text selected when clicking 'Quick Parts' you will be able to use the 'Save Selection to Quick Part Gallery...' item to add the selected text into the Gallery. You can choose between any of the templates available, including  the 'Building Blocks'  template, the attached template and any Global or add-in templates associated with the document.

The facility can be can be used programatically. Here is some code from the VBA Help file to show the principle of inserting into the document
Dim objTemplate As Template
Dim objBB As BuildingBlock

Set objTemplate = Templates(1)
Set objBB = objTemplate.BuildingBlockEntries(1)

objBB.Insert ActiveDocument.Paragraphs(1).Range

Open in new window

0
 

Author Closing Comment

by:Basicfarmer
ID: 40450383
I have poured over this and it is very good stuff. Thanks for your comments...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question