Results 1 to 2 of 2

Thread: [RESOLVED] Find/Replace using New Sheet

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    10

    Resolved [RESOLVED] Find/Replace using New Sheet

    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
    

  2. #2

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    10

    Re: Find/Replace using New Sheet

    I solved the problem myself. What I needed to do was make sure that it was reading from the activesheet, so I added the statement

    Sheets("Terms").Activate

    and then changed

    Call Chin_Eng_new(Cells(n, 1).Value, Cells(n, 2).Value)

    to

    Call Chin_Eng_new(ActiveSheet.Cells(n, 1).Value, ActiveSheet.Cells(n, 2).Value)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width