+ Reply to Thread
Results 1 to 6 of 6

Excel 2013 - VBA Find and Replace

Hybrid View

  1. #1
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Excel 2013 - VBA Find and Replace

    Untested, but is sound to my eye. In your Excel workbook

    1) create a sheet called LIST
    2) List the SEARCH strings in column A
    3) List the REPLACE strings in column B

    NOTE: Be wary of small search strings that might be a "substring" of other search strings. Order your LIST by the longest searches to the smallest, that should help.

    4) Now run this macro from that same workbook

    Sub DocSearch()
    Dim wdApp As Object, wdDoc As Object
    Dim SrchRNG As Range, SrchVAL As Range
    
    Set SrchRNG = ThisWorkbook.Sheets("LIST").Range("A:A").SpecialCells(xlConstants)
        
    Set wdApp = CreateObject("word.application")
    wdApp.Visible = True
    Set wdDoc = wdApp.Documents.Open("C:\Documents and Settings\Owner\My Documents\downloads\work\M-F-380.1.doc")
        
    For Each SrchVAL In SrchRNG
        With wdDoc.Content.Find
            .Text = SrchVAL.Text
            .Replacement.Text = SrchVAL.Offset(, 1).Text
            .Wrap = wdFindContinue
            .Execute Replace:=wdReplaceAll
        End With
    Next SrchVAL
    
    Set wdApp = Nothing
    Set wdDoc = Nothing
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  2. #2
    Registered User
    Join Date
    07-19-2013
    Location
    Scranton, Pa
    MS-Off Ver
    Excel 2013
    Posts
    14

    Re: Excel 2013 - VBA Find and Replace

    I am getting a Run-time error '1004': Application-defined or object-defined error when trying to compile the code

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Excel 2013 VBA - Find value in named range
    By riffology in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-18-2014, 03:36 PM
  2. Replies: 3
    Last Post: 07-20-2014, 11:46 AM
  3. Code for find an replace (word 2013)
    By capitala in forum Word Programming / VBA / Macros
    Replies: 1
    Last Post: 02-03-2014, 06:57 AM
  4. Link Excel 2013 to Word 2013
    By drosen99 in forum Word Formatting & General
    Replies: 20
    Last Post: 02-26-2013, 08:20 PM
  5. find in excel replace in word: find/replace text in text boxes and headers
    By dean.rogers in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-10-2012, 12:40 PM

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