Solved

Add Documents to a word document

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

815 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

10 Experts available now in Live!

Get 1:1 Help Now