Results 1 to 33 of 33

Find/Replace Macro to Word

Threaded View

  1. #1
    Registered User
    Join Date
    09-28-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    24

    Find/Replace Macro to Word

    Hi,

    I have the following Macro;

    Sub Replacing()
    
        Dim sFile   As String
        Dim wrdApp  As Word.Application
        Dim wrdDoc  As Word.Document
    
        sFile = "Pack"
        Set wrdApp = New Word.Application
    
        With wrdApp
            .Visible = True
            Set wrdDoc = .Documents.Open("C:\Users\Admin\Desktop\" + sFile + ".doc")
    
            With .Selection.Find
                .ClearFormatting
                .Replacement.ClearFormatting
                .Text = "NAME1" + "NAME2"
                .Replacement.Text = Range("C2") + Range("C3")
                .Forward = True
                .Wrap = wdFindContinue
                .Format = False
                .MatchCase = False
                .MatchWholeWord = False
                .MatchWildcards = False
                .MatchSoundsLike = False
                .MatchAllWordForms = False
                .Execute Replace:=wdReplaceAll
            End With
        End With
    End Sub
    .Text = "NAME1"
    .Replacement.Text = Range("C2")

    This works for all NAME1 entries in the Word document but I want to have multiple searches for example;

    .Text = "NAME1" & "NAME2"
    .Replacement.Text = Range("C2") & Range("C3")

    So that it will replace NAME1 and 2 with what is in C2 and C3. I want to do about a hundred of these.

    Also I would like some assistance on how to modify this macro so the user cannot interact with it and once the changes are complete it Prints and Closes the word document.

    Many thanks.
    Last edited by macronoob123; 10-01-2011 at 09:28 AM.

Thread Information

Users Browsing this Thread

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

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