I am using a macro to take words from excel (column 1: chinese word, column 2: english word). The code works fine for the first sheet, but when I move to sheet 2 labeled "terms", then It doesn't execute the find/replace, and I'm not sure why
HTML Code:Option Explicit 'the document Dim Trans_doc As Object 'the application Dim WD As Object Dim n As Integer Dim numb As Integer Private Sub CommandButton1_Click() Const trans_document As String = "C:\Translate\ChineseOMM.doc" Set WD = CreateObject("Word.Application") WD.Visible = True Set Trans_doc = WD.Documents.Open(trans_document) numb = InputBox("Enter number of words in database") For n = 2 To numb Call Chin_Eng_new(Cells(n, 1).Value, Cells(n, 2).Value) Next n Sheets("Terms").Select numb = InputBox("number of vocab terms") For n = 2 To numb Call Chin_Eng_new(Cells(n, 1).Value, Cells(n, 2).Value) Next n WD.Activate Trans_doc.SaveAs "C:\Translate\EnglishOMM.doc" Trans_doc.Close WD.Quit Set Trans_doc = Nothing Set WD = Nothing End Sub Sub Chin_Eng_new(Chin As String, Eng As String) Const wdReplaceAll = 2 With Trans_doc.Range.Find .ClearFormatting .Replacement.ClearFormatting .Execute FindText:=Chin, _ ReplaceWith:=Eng, _ Replace:=wdReplaceAll .ClearFormatting End With End Sub




Reply With Quote