Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-29-2018, 01:52 AM
Sc0tt1e Sc0tt1e is offline Auto generation of a Glossary of terms Windows 10 Auto generation of a Glossary of terms Office 2010 64bit
Novice
Auto generation of a Glossary of terms
 
Join Date: Mar 2018
Posts: 1
Sc0tt1e is on a distinguished road
Default Auto generation of a Glossary of terms

Hi all,



I am attempting to put together some code that will review a project document that will be manually created (where the code will be based) and the code will check a list of terms held in another document (terms doc) against the content of the project doc and if the words in the terms doc are present in the main doc I need a table to be inserted in the end of the document containing the word and the description.

I found the below code which is similar but only list the word and the page it was found on and I was wondering if anyone could help me with what would need adjusting to make this work for my required purposes (or if they have something that would work) I would be grateful for the assistance/support?

Code:
Sub TabulateKeyTerms()
Application.ScreenUpdating = False
Dim Doc As Document, RefDoc As Document, Rng As Range
Dim StrTerms As String, strFnd As String, StrPages As String
Dim i As Long, j As Long, StrOut As String, StrBreak As String
 
StrOut = "Term" & vbTab & "Pages" & vbTab & "Term" & vbTab & "Pages" & vbCr
Set Doc = ActiveDocument
Set RefDoc = Documents.Open("Drive:\FilePath\KeyTerms.doc", AddtorecentFiles:=False)
StrTerms = RefDoc.Range.Text
RefDoc.Close False
Set RefDoc = Nothing
 
' I think this searches the content of the document against the terms of ref doc. strFind loops each term one at a time
For i = 0 To UBound(Split(StrTerms, vbCr))
  strFnd = Trim(Split(StrTerms, vbCr)(i))
  If strFnd = "" Then GoTo NullString
  StrPages = ""
  With Doc.Content
    With .Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Format = False
      .Text = strFnd
      .Wrap = wdFindStop
      .MatchWholeWord = True
      .MatchWildcards = False
      .MatchCase = True
      .Execute
    End With
 
' I think this counts the page numbers if there is more than 1 reference to the term?
    j = 0
    Do While .Find.Found
      If j <> .Duplicate.Information(wdActiveEndPageNumber) Then
        j = .Duplicate.Information(wdActiveEndPageNumber)
        StrPages = StrPages & j & " "
      End If
      .Find.Execute
    Loop
 
'I think this splits out the page numbers after the term with a space then a comma and space between each page number?
    StrPages = Replace(Trim(StrPages), " ", ",")
    If StrPages <> "" Then
      If i Mod 2 = 0 Then StrBreak = vbTab Else StrBreak = vbCr
      StrOut = StrOut & strFnd & vbTab & ParsePageRefs(StrPages) & StrBreak
    End If
  End With
 
NullString:
Next I
 
' I think this creates the table ? (Will I need 4 columns)
Set Rng = Doc.Range.Characters.Last
With Rng
  .InsertAfter vbCr & Chr(12) & StrOut
  .Start = .Start + 2
  .ConvertToTable Separator:=vbTab, Numcolumns:=4, AutoFitBehavior:=wdAutoFitContent, AutoFit:=True
  With .Tables(1).Rows.First.Range
    .ParagraphFormat.Alignment = wdAlignParagraphCenter
    .Font.Bold = True
  End With
End With
 
Application.ScreenUpdating = True
End Sub
 
 
' I have no idea what this is doing??????????????
Function ParsePageRefs(StrPages As String)
Dim ArrTmp(), i As Integer, j As Integer, k As Integer
ReDim ArrTmp(UBound(Split(StrPages, ",")))
For i = 0 To UBound(Split(StrPages, ","))
  ArrTmp(i) = Split(StrPages, ",")(i)
Next
For i = 0 To UBound(ArrTmp) - 1
  If IsNumeric(ArrTmp(i)) Then
    k = 2
    For j = i + 2 To UBound(ArrTmp)
      If CInt(ArrTmp(i) + k) <> CInt(ArrTmp(j)) Then Exit For
      ArrTmp(j - 1) = ""
      k = k + 1
    Next
    i = j - 1
  End If
Next
ParsePageRefs = Replace(Replace(Replace(Replace(Join(ArrTmp, ","), ",,", " "), " ,", " "), "  ", " "), " ", "-")
End Function
Attached Files
File Type: docx ToR.docx (32.6 KB, 9 views)

Last edited by Sc0tt1e; 03-29-2018 at 03:35 AM. Reason: Included terms of ref document
Reply With Quote
  #2  
Old 03-29-2018, 01:25 PM
macropod's Avatar
macropod macropod is offline Auto generation of a Glossary of terms Windows 7 64bit Auto generation of a Glossary of terms Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
Sub TabulateKeyTerms()
Application.ScreenUpdating = False
Dim Doc As Document, RefDoc As Document, Rng As Range
Dim StrTerms As String, strFnd As String, StrPages As String
Dim r As Long, j As Long, StrOut As String, StrBreak As String
Set Doc = ActiveDocument
Set RefDoc = Documents.Open("Drive:\FilePath\KeyTerms.doc", ReadOnly:=True, AddToRecentFiles:=False)
For r = RefDoc.Tables(1).Rows.Count To 1 Step -1
  strFnd = Trim(Split(RefDoc.Tables(1).Cell(r, 1).Range.Text, vbCr)(0))
  With Doc.Content
    With .Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Format = False
      .Text = strFnd
      .Wrap = wdFindStop
      .MatchWholeWord = True
      .MatchWildcards = False
      .MatchCase = True
      .Execute
    End With
    If .Find.Found = False Then RefDoc.Tables(1).Rows(r).Delete
Next r
Set Rng = Doc.Range.Characters.Last
Rng.FormattedText = RefDoc.Tables(1).Range.FormattedText
RefDoc.Close False
Set Rng = Nothing: Set RefDoc = Nothing
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto generation of a Glossary of terms Creating sidebar (or wide margin) for glossary items almagary Word Tables 3 01-23-2018 04:34 PM
Auto generation of a Glossary of terms Best Practice for Indexing Multiple Word Terms and Sub-Terms jhy001 Word 4 11-06-2017 02:08 PM
Auto Generation of Hyperlinks cooloox Excel Programming 4 03-27-2017 06:47 AM
Auto generation of a Glossary of terms Keyboard shortcut for glossary styles Jennifer Murphy Word 1 01-06-2016 09:19 AM
Auto generation of a Glossary of terms Invoice Number Generation mrphilk Excel 2 06-08-2010 12:39 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:18 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft