Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro to Preview other word document

Status
Not open for further replies.

bernie321

Programmer
Jan 7, 2004
477
GB
Hi

We use a macro to insert pre-typed statements of text from other word documents.

As we require users to only use managment checked text we use an initiation file to store the list of documents and a 'friendly' name for users.

We want to take this one step further and when users click on an item in the listbox either a preview will appear on the form next to it or a set propertion of the text (eg the first 100 characters).

What controls could I use for this and could anyone point me towards some example code that I could develop.

Any help would be greatly appreciated

Thanks B
 
pls clarify u r requirements again.

1. listbox? this is activex listbox IN the document? listbox box on UserForm?

2. r text portion in Word doc? if so, any particular reason use this rather than AutoText? Altho, can certainly think of reason myself - keeps entries in one location.

3. how r text "chunks" located in source doc? Bookmark ranges? FormFields?

4. r authorized text chunks ONLY text in the docs? or does the source doc have multiple chnuks?

Suggestions:

a) one source doc with all approved chunks
b) each chunk is bookmark RANGE - not bookmark location.
c) each chunk has reasonable name
d) if selection procedure is UserForm, load listbox with bookmark names.

SIDEBAR - why listbox? listbox allows multiple selections, but if multiple selections done, how u determine WHERE to put text???? Seems combobox better.

say 20 chunks of text in source doc (SourceChunks.Doc),; each chunk set as bookmark RANGE (not locations). this mean grab bookmark, can grab text.

on userform initialize, combobox loads sourcechunks bookmark names:
Code:
sub userform1_initialize()
dim aBookmark as bookmark
dim docSource as document
dim i as integer
dim var
documents.open filename:="c:\whatever\sourcechunks.doc"
set docSource = activedocument
i = 1
on error resume next
for var = 1 to docSource.bookmarks.count
  combobox1.additem docSource.bookmarks(i).name
  i = i + 1
next
combobox1.listindex = 0
end sub

a commandbutton 2 grab selected item from combobox, insert at selection point

Code:
sub commandbutton1_click()
selection.typetext text:=docSource.bookmarks(combobox1.text) _
   .range.text
end sub

make SURE u release docSource object when u r done, close first; this could b in the form close event, in commandbutton event - depends on if doing multiple text insertions..if so, make form non-modal so user can navigate through doc finding other location to insert text.

docsource close (wddonotsavechanges)
set docSource = nothing
 
Hi Phaed

Thanks for the info.

Sorry I dont think I explained our current situation very well:

We already have a system which inserts the text into the documents, we have hundreds of word documents containing 1+ paragraphs of text - users then build up documents using a userform with a subcatagory combo box and by selecting items from a list box.

I wish to add to this a 'preview' section such as the one that is available in the Open dialogue of Word 2000+

But I do not know of the controls that are available to do this.

Thanks B
 
again, i ask for explanation of HOW u r doing this.

there must b some mechanism to grab the choice. if i know the mechanism then easy to have preview.

the control would simply be a Label on form. whatever is the content that WILL BE inserted, is simply displayed into the Caption property of the label.

eg.

user selects item 19 of the combobox list. what is mechanism to get whatever item 19 represents? if list item 19 represents the text paragraph 3 from document # 14 then, instead of inserting that text, simply display the text (or portion thereof) in a Label caption on the form. user goes, oh yes, that is the one...presses OK button, and mechanism to insert does its job. user goes, no not that one...selects a different item choice...which then displays in label.Caption.

my point is that DESIGN has 2 b thought of. Depending on mechanism (which u have not explained), the list itself can be self explanatory.

however, that is the way to "Preview" whatever is the text, dump it into a Label with the .caption property = the text itself, or a enough of it for user to determine if correct one.
 
Sorry Phaed

The whole of each document is imported, a header name is passed to a function which is used the identify the filename and path from an ini file.

THanks

B
 
then again, pls explain. still trying 2 get HOW u r working this.

"header name is passed to a function" - huh? where header name from? & what u mean by "header name"?

see if understand. u have a listbox. there r items in list. user selects item. selected item then.....reads from ini file and uses THAT to identify file, and THEN "imports" file? do i have this right?

actually, it matters not. in any scenario, an selected item causes code 2 go 2 file & read. grab first part and display it.

what am i missing here?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top