Solved

Add Documents to a word document

Posted on 2014-11-17
4
195 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
  • 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now