Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Add Documents to a word document

Posted on 2014-11-17
4
Medium Priority
?
209 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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

876 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