Solved

Add Documents to a word document

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
My experience with Windows 10 over a one year period and suggestions for smooth operation
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
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…

920 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

12 Experts available now in Live!

Get 1:1 Help Now