Results 1 to 5 of 5

Mailmerge Search & Replace

Threaded View

  1. #1
    Registered User
    Join Date
    12-22-2009
    Location
    Pune, India
    MS-Off Ver
    Excel 2003
    Posts
    30

    Mailmerge Search & Replace

    HI,
    I am using the macro to mailmerge data from Excel to word. When merge is done I am finding it difficult to find a specific word and replace it with other word. Below is the code i am using. Fins and replace string is not working in this code.

    Please can any one help me on this one.

    Function MMGA()
    With Session
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = True
    With objWord
    Set objMMMD = objWord.Documents.Open("c:\Doc trial2.doc ")
    objMMMD.Activate
    objMMMD.MailMerge.OpenDataSource _
    name:="C:\ABC.xls", _
    SQLStatement:="SELECT * FROM [Sheet3$]"
    With objMMMD.MailMerge
    .Destination = wdSendToNewDocument
    .SuppressBlankLines = True
    With .DataSource
    .FirstRecord = wdDefaultFirstRecord
    .LastRecord = wdDefaultFirstRecord
    End With
    .Execute
    
    With .Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = "Ind"
        .Replacement.Text = "India"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = bWild
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Execute Replace:=wdReplaceAll
    End With
    
    End With
    End With
    objMMMD.Close SaveChanges:=wdDoNotSaveChanges
    Set objMMMD = Nothing
    If bCreatedWordInstance Then
    objWord.Quit
    End If
    Set objWord = Nothing
    ' open excel and delete data
     Set Xl = GetObject("C:\ABC.xls")
        Xl.Application.Visible = True
        Xl.Parent.Windows(1).Visible = True
        Xl.activesheet.Unprotect "abc12345"
        Xl.activesheet.Cells.Clear
        Xl.activesheet.Protect "abc12345"
        Xl.Application.Workbooks("ABC.xls").save
        Xl.Application.Visible = True
        Xl.Parent.Windows(1).Visible = True
        Xl.Application.Workbooks("lpm.xls").Close
    
    End With
    End Function
    Last edited by PooH; 07-19-2010 at 01:27 PM. Reason: Added Code tags

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