Results 1 to 5 of 5

Excel VBA - Word to search for part of a word and replace full word

Threaded View

  1. #1
    Registered User
    Join Date
    12-13-2016
    Location
    bradford
    MS-Off Ver
    2010
    Posts
    10

    Excel VBA - Word to search for part of a word and replace full word

    Hello there,

    (post changed if your wondering i you have seen it before)

    I have the following code that is mostly from google as a starting point:

    
    Sub DocSearch()
    
    Application.ScreenUpdating = False
        Dim wdApp As Object, wdDoc As Object
        Set wdApp = CreateObject("word.application")
        wdApp.Visible = True
        Set wdDoc = wdApp.Documents.Open("C:\Users\Samsung\Desktop\Charlie Work\vba\word replacement\datetest.docx")
    
        
        
        With wdDoc.Content.Find
            .text = 4500
            .Replacement.text = "4500xxxx"
            .Wrap = wdFindContinue
            .Execute Replace:=wdReplaceAll
        End With
        
        wdDoc.SaveAs ("C:\Users\Samsung\Desktop\Charlie Work\vba\word replacement\datetest did it work.docx")
        wdDoc.Close
    
        Set wdApp = Nothing: Set wdDoc = Nothing
        
    Application.ScreenUpdating = True
    End Sub
    however i cannot determine a way to use the code to replace an entire section of text, rather than just a part of it: e.g searching 4500 and replacing it with 45001111 if the text to replace is 4500xxxx

    45001111xxxx

    were i was wondering if it can be replaced as just:

    45001111

    hope that makes sence? any thoughts?
    Attached Files Attached Files
    Last edited by charlie543; 12-23-2016 at 06:59 PM. Reason: moderator correction

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Help with macro to find a specific word and replace the entire cell with the return word.
    By BG1983 in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 08-24-2015, 09:40 PM
  2. [SOLVED] Excel macro- Find replace an itallic font word with a regular word?
    By thisisaboutwork in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-08-2013, 01:48 PM
  3. Need help with Excel-to-Word find and replace macro based on word filename
    By EnterTheSerpent in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-16-2013, 12:48 PM
  4. Search and Replace... from Excel to Word
    By Xx7 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-27-2011, 03:05 PM
  5. Replace word in MS Word with varable from MS Excel
    By odo in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-05-2009, 05:18 PM
  6. Replies: 1
    Last Post: 12-20-2005, 10:00 AM
  7. [SOLVED] Newbie trying to search and replace word in word doc from excel
    By kaiser in forum Excel General
    Replies: 5
    Last Post: 09-13-2005, 07:06 AM

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