Results 1 to 13 of 13

Thread: Macro to pick information from notepad

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular
    Joined
    Aug 2006
    Posts
    79
    Location

    Macro to pick information from notepad

    Hi All,

    The following macro has a SearchArray and a ReplaceArray, to find and replace words. I am looking forward to modify this macro that instead of using the above arrays, it uses two .txt files to find and replace (image attached). The .txt files will be placed in My Document folder (default folder), or at certain specific drive whatever works. The reason being that it is easy for the user to modify and add words into a notepad and not doing corrections in the macro code.

    [VBA]Sub TestMacro()
    Dim SearchArray As Variant
    Dim ReplaceArray As Variant
    Dim myRange As Range
    Dim i As Long
    Dim pFind As String
    Dim pReplace As String
    SearchArray = Array("first name", "last name", "home following for", "over the time")
    ReplaceArray = Array("First Name", "Last Name", "who I am following for", "over time")
    Set myRange = Selection.Range
    For i = LBound(SearchArray) To UBound(SearchArray)
    pFind = SearchArray(i)
    pReplace = ReplaceArray(i)
    With myRange.Find
    .Text = pFind
    .Replacement.Text = pReplace
    .MatchWholeWord = True
    .Replacement.Highlight = True
    .Execute Replace:=wdReplaceAll
    End With
    Next
    End Sub[/VBA]

    The first question is, is it possible? Secondly, will it be slow? As at certain times I need to put in a few hundred sets of words there, although there is no problem in running the macro in a present code.

    Thanks, and looking forward for a help.
    Attached Images Attached Images

Posting Permissions

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