Closed Thread
Results 1 to 3 of 3

Find & Replace text in Word 2010 with Excel 2010 values.

  1. #1
    Registered User
    Join Date
    11-30-2011
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Find & Replace text in Word 2010 with Excel 2010 values.

    I'm very new to Excel VBA/Macros (this week) and consider myself an above average user of Excel.

    I am looking for a way to find and replace text in a Word document based on data in 2 columns in Excel.

    I need to search Word and find Test Case #, match that number to column A in Excel and replace it with the value in column B.

    I have attached a sample of the 2 files I am working with.

    So for the first one:

    Word: "Test Case 1009: Create and Manage an Event"

    Excel:
    ID Test Case Identifier
    1009 002-01

    I need to replace “1009” in Word with “002-01” from Excel.

    Thanks!

    R/Phil
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    11-30-2011
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Find & Replace text in Word 2010 with Excel 2010 values.

    I found the answer in a Word Forum...

    All I needed to do is enter the correct path to the Excel file and update "For idx = 1 To 100" to a number larger than the number of rows in ID.xlsx

    Sub FindReplaceExcel()
    Dim xlApp 'As Excel.Application
    Dim xlWB 'As Excel.Workbook
    Dim idx As Integer

    Set xlApp = CreateObject("Excel.Application")
    Set xlWB = xlApp.Workbooks.Open("C:\Path to File\ID.xlsx")

    For idx = 1 To 400

    'MsgBox "Replacing " & xlWB.Worksheets(1).Cells(idx, 1) & " by " & xlWB.Worksheets(1).Cells(idx, 2)

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = xlWB.Worksheets(1).Cells(idx, 1)
    .Replacement.Text = xlWB.Worksheets(1).Cells(idx, 2)
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchControl = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

    Next

    xlWB.Close False
    xlApp.Quit

    Set xlWB = Nothing
    Set xlApp = Nothing

    End Sub

  3. #3
    Registered User
    Join Date
    01-14-2015
    Location
    Hyderabad
    MS-Off Ver
    2007
    Posts
    2

    Re: Find & Replace text in Word 2010 with Excel 2010 values.

    I have a doubt on find replacing of whole words

    If I want the macro to replace the word 'ice' with 'cold', if it sees a word like 'nice' it will replaced it to 'ncold'.

    how to resolve the these type of errors

    kindly reply

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1