+ Reply to Thread
Results 1 to 6 of 6

Excel 2013 - VBA Find and Replace

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

    Excel 2013 - VBA Find and Replace

    I am looking for a simple VBA that will reference specific cells in Excel and use this date to do a find and replace in Word.

    Example:

    Cell B2 in Excel = John Smith

    I want the VBA to take John Smith, search a specified Word document using that information, and replace all instances of John Smith with whatever value I choose, such as Sally Smith.

    I would like to be able to repeat this process for as many cells as I please.

    I found the code below, but it's potential seems limited to me. You have to manually enter the find and replace text in the VBA. I am looking for a way to make this automated.

    I have done some searching and found all the different elements I am looking for. I can't seem to find anything that includes all my requests in one VBA.

    Any help would be greatly appreciated!

    Thanks!

    Please Login or Register  to view this content.

  2. #2
    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

    Please Login or Register  to view this content.
    _________________
    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!)

  3. #3
    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

  4. #4
    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

    Perhaps remove OPTION EXPLICIT from the top of the module if you have that there...?

    Can you post the Excel and the Word doc so I can test myself?

  5. #5
    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 discovered the problem, I had to add the Microsoft Word 15.0 Object Library reference. After turning this on, the program worked exactly as intended.

    Thanks!

  6. #6
    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

    As it appears you've reached a conclusion, I've marked this thread SOLVED for you.
    FYI, this is done through the Thread Tools located above the first post in this thread. Thanks.

+ 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