Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #9  
Old 09-15-2014, 03:36 PM
macropod's Avatar
macropod macropod is offline Find a word in doc1, search for it in dictionary doc2, copy the meaning from doc 2 to doc 1 Windows 7 64bit Find a word in doc1, search for it in dictionary doc2, copy the meaning from doc 2 to doc 1 Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,518
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 AddDefinitions()
Application.ScreenUpdating = False
Dim FRDoc As Document, FRList, j As Long, StrFnd As String, StrRep As String
 'Load the strings from the reference doc into a text string to be used as an array.
Set FRDoc = Documents.Open("Drive:\FilePath\Dictionary.doc")
FRList = FRDoc.Range.Text
FRDoc.Close False
Set FRDoc = Nothing
With ActiveDocument.Range
  .Font.ColorIndex = wdBlue
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .MatchWholeWord = True
    .MatchCase = True
    .Format = False
    .Wrap = wdFindContinue
    .MatchWildcards = False
    'Process each word from the Check List. Tab-delimited strings are assumed, formatted as:
    'Term <Tab> Definition
    For j = 0 To UBound(Split(FRList, vbCr)) - 1
      .Text = "(" & Split(Split(FRList, vbCr)(j), vbTab)(0) & ")"
      .Replacement.Text = "^&-" & Split(Split(FRList, vbCr)(j), vbTab)(1)
      .Execute Replace:=wdReplaceAll
    Next
    .MatchWildcards = True
    .Format = True
    .Text = "\(*\)"
    .Replacement.Text = "^&"
    .Replacement.Font.ColorIndex = wdRed
    .Execute Replace:=wdReplaceAll
  End With
End With
Application.ScreenUpdating = True
End Sub
Note that you'll need to replace 'Drive:\FilePath\Dictionary.doc' with your
actual filename & path.

The above code assumes your dictionary has each word separated from its definition by a TAB and that there's only one definition per paragraph. The dictionary document must not have any content that doesn't conform to this (i.e. no empty paragraphs, no paragraphs lacking tabs, no paragraphs with more than one entry). For speed, the macro first turns the whole document blue, does the definition additions, then turns the original bracketed words red again. Anything not originally bracketed with thus end up blue.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 

Tags
macro find and replace, macro vba word, macros



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find a word in doc1, search for it in dictionary doc2, copy the meaning from doc 2 to doc 1 Find what box in Find and replace limits the length of a search term Hoxton118 Word VBA 7 06-10-2014 05:05 AM
Won't find in search ep2002 Word 3 10-31-2012 05:24 PM
Find a word in doc1, search for it in dictionary doc2, copy the meaning from doc 2 to doc 1 Macro that can find phrase and then find another and copy jperez84 Word VBA 10 09-19-2012 04:48 PM
Find a word in doc1, search for it in dictionary doc2, copy the meaning from doc 2 to doc 1 where we can find the meaning for all the marks that Word uses? Jamal NUMAN Word 2 06-26-2011 09:49 AM
Search Replace Copy dblack7211 Word 0 05-05-2010 01:19 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:27 PM.


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