Central Glossary to feed multiple documents

  • Hi there - I just don't know if this task is possible, and if it's starting to look ridiculously difficult we can just call it a day.


    BTW - searches on glossary and appendix returned nothing...


    I hope you've got your thinking caps on...


    I have a dictionary list - lets say it has 10 entries in it (which could be either a single word, or a short phrase) and we'll officially call these Entries and for each of the 10 entries there is a description (exactly like a dictionary), which we'll officially call Description. This list is in a word doc called List.doc.


    I now create another word doc - Doc 1 - and in it I may use a word that
    is contained in the List document.


    What I'm trying to find out is this: is it possible to check through Doc 1 to find out in any word used in it matches an Entry from List.doc?


    If a match is found then the Entry and it's Description are copied into Doc 1 and pasted into a Glossary at the bottom.


    The reason for doing this is we have a glossary of several hundred words and phrases and we draw reports that might mention one or many of these words, but we don't want to have to print this glossary every time we do a report (because we do thousands of reports!). We only want to include in each report those terms that are actually used in that instance of the report.


    I hope that's clear - as always any help much appreciated.


    Mark

    I consider myself lucky. I started out with nothing and, well, I still have most of it.

  • Re: Central Glossary to feed multiple documents


    Hi Mark,


    This is most definitely possible, but it is quite a large piece of development and personally I don't have the knowledge of word (my background is in Excel) to be able to help. I'm sure there are quite a few people who use this site who could write something to do what you require, but like I said it is a pretty major thing for someone here to start from scratch.


    Hope you can find help,
    Ian

  • Re: Central Glossary to feed multiple documents


    Ian,


    I agree it's a large piece of development - some of the issues I've thought of are


    1 - how to identify whether a word in Doc 1 is on the list of Entries in List.doc
    2 - how to ensure that if a phrase is repeated multiple times in Doc 1, it only comes back once in the Glossary at the end of Doc 1.


    I did think of more, but until we try to get into the coding and see the possibilty/impossibility there's no point in laying them all out.


    Still it is an interesting problem (I think) and even if it weren't finished it'd be great to see, even as a generality, what route solutions might take.


    Cheers,


    Mark

    I consider myself lucky. I started out with nothing and, well, I still have most of it.

  • Re: Central Glossary to feed multiple documents


    I think your main problem occurs in how to identify the terms in List.doc that need searching for. Actually searching for them in the Doc1 and adding the words and definitions isn't too much of a problem as the macro can automate the search and just store those terms that return greater than 0 results, then print them out later.


    The problem is getting the macro to identify what text in List1 is a term/word that requires searching for and what is simply a definition, title or other part of the document. If the glossary was in Excel it would be easier as you could separate the terms into cells with the descriptions in different cells. The other way to do it (that i can think of) is to have a unique seperator, i.e. a character or string of characters that appears in List.doc ONLY when seperating the end of a term/word from its definition, then we could get the macro to tell when it starts and stops by the occurrances of the seperators.


    Cheers,
    Ian

  • Re: Central Glossary to feed multiple documents


    Ian,


    Let's investigate the Excel option then - I'm certainly not straitjacketed into using Word for List.doc.


    If we can find a solution using Excel, let's go for it.


    I'm surprised (and now quietly filling with hope) when you say "Actually searching for them in the Doc1 and adding the words and definitions isn't too much of a problem as the macro can automate the search and just store those terms that return greater than 0 results, then print them out later."


    I thought that was going to be one of the hard parts.


    Shall we run with this then, and see where it takes us?


    Thanks for your suggestions so far.


    Mark

    I consider myself lucky. I started out with nothing and, well, I still have most of it.

  • Re: Central Glossary to feed multiple documents


    Andy, Ian,


    My real apologies for the delay in getting this files uploaded - I've been crushed under a massive end of Feb deadline, and have only been able to get my head above water this morning.


    Here are two files - all I've done is found a (IT-focused) glossary online and mixed in some of the terms from it into some sports stories. I've highlighted the IT keywords in bolded blue for easy identification.


    Thanks for your continuing interest.


    Mark

  • Re: Central Glossary to feed multiple documents


    Hi,


    This should build you a glossary at the end of your document.
    Add the following to the List.xls file. Include a reference to the Word Library. Within VBE use the menu Tools > References.[vba]Sub BuildGlossary()
    '
    ' Include Reference in Word Library
    '
    Dim wrdApp As Word.Application
    Dim wrdDoc As Word.Document
    Dim rngGlossary As Range
    Dim rngTerm As Range
    '
    With Sheet1
    Set rngGlossary = .Range("A1:A" & .Range("A1").End(xlDown).Row)
    End With

    Set wrdApp = CreateObject("Word.Application")
    wrdApp.Visible = True
    ' change location to suit
    Set wrdDoc = wrdApp.Documents.Open("C:\Temp\doc.doc")
    With wrdApp.Selection
    ' end of document
    .EndKey wdStory
    ' new page and add glossary heading
    .InsertBreak wdPageBreak
    .TypeText Text:="GLOSSARY"
    .InsertBreak wdLineBreak
    .InsertBreak wdLineBreak
    End With

    For Each rngTerm In rngGlossary
    If WordFind(rngTerm.Text, wrdDoc) Then
    With wrdApp.Selection
    .EndKey wdStory
    .TypeText Text:=rngTerm.Value
    .InsertBreak wdLineBreak
    .TypeText Text:=vbTab & rngTerm.Offset(0, 1)
    .InsertBreak wdLineBreak
    .InsertBreak wdLineBreak
    End With
    End If
    Next
    wrdDoc.Close True

    Set wrdDoc = Nothing
    Set wrdApp = Nothing

    End Sub
    Function WordFind(Text As String, Doc As Word.Document) As Boolean

    Dim rngFind As Word.Range

    With Doc.Content.Find
    .Text = Text
    .MatchCase = False
    .Execute
    WordFind = .Found
    End With

    End Function[/vba]

    [h4]Cheers
    Andy
    [/h4]

  • Re: Central Glossary to feed multiple documents


    Andy,


    re: adding a reference - is that simply adding a ref to Microsoft Word 8.0 Object Library. Or is it more complicated than that?

    I consider myself lucky. I started out with nothing and, well, I still have most of it.

  • Re: Central Glossary to feed multiple documents


    Andy,


    You beaut. That's genuinely amazing - and works a complete treat. For some reason my computer didn't like the


    Code
    With Sheet1 
            Set rngGlossary = .Range("A1:A" & .Range("A1").End(xlDown).Row) 
        End With


    which isn't the first time, but I fixed it with this little snippet


    Code
    Dim wsSource As Worksheet
        
        Set wsSource = Sheet1
        
        With wsSource
            Set rngGlossary = .Range("A1:A" & .Range("A1").End(xlDown).Row)
        End With


    You have solved what was a thorny problem indeed.


    I truly appreciate your help. If I'm ever in Essex I'll owe you a pint.


    Mark

    I consider myself lucky. I started out with nothing and, well, I still have most of it.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!