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
Bookmarks