Large find/replace in Word using VBA











up vote
2
down vote

favorite












I have a large amount of data from a hardware device that needs to be cleaned up so it can be analyzed in Excel.



I wrote a simple find/replace VBA macro in word to convert it to .csv, but the macro takes a long time to run through large sets of data.



I'm looking for suggestions on a faster way to code this. Alternately, if there is another option for cleaning the data that would work better than Word and VBA, I'm willing to switch to it.



Sub CleanText()


Application.ScreenUpdating = False

' clean data for import to excel
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p" & "^p"
.Replacement.Text = "wvw"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p"
.Replacement.Text = ","

End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "wvw"
.Replacement.Text = "^p"
.Forward = True

End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "$GPGGA" & "(*)" & "$GPRMC"
.Replacement.Text = "$GPRMC"
.MatchWildcards = True

End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "W" & "(*)" & "S"
.Replacement.Text = "W,"
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "V" & "(*)" & "S"
.Replacement.Text = "V,,,,,"
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "$GPRMC,"
.Replacement.Text = ""
End With
Selection.Find.Execute Replace:=wdReplaceAll

Application.ScreenUpdating = True

End Sub









share|improve this question




























    up vote
    2
    down vote

    favorite












    I have a large amount of data from a hardware device that needs to be cleaned up so it can be analyzed in Excel.



    I wrote a simple find/replace VBA macro in word to convert it to .csv, but the macro takes a long time to run through large sets of data.



    I'm looking for suggestions on a faster way to code this. Alternately, if there is another option for cleaning the data that would work better than Word and VBA, I'm willing to switch to it.



    Sub CleanText()


    Application.ScreenUpdating = False

    ' clean data for import to excel
    '
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "^p" & "^p"
    .Replacement.Text = "wvw"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "^p"
    .Replacement.Text = ","

    End With
    Selection.Find.Execute Replace:=wdReplaceAll

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "wvw"
    .Replacement.Text = "^p"
    .Forward = True

    End With
    Selection.Find.Execute Replace:=wdReplaceAll

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "$GPGGA" & "(*)" & "$GPRMC"
    .Replacement.Text = "$GPRMC"
    .MatchWildcards = True

    End With
    Selection.Find.Execute Replace:=wdReplaceAll

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "W" & "(*)" & "S"
    .Replacement.Text = "W,"
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "V" & "(*)" & "S"
    .Replacement.Text = "V,,,,,"
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "$GPRMC,"
    .Replacement.Text = ""
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

    Application.ScreenUpdating = True

    End Sub









    share|improve this question


























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I have a large amount of data from a hardware device that needs to be cleaned up so it can be analyzed in Excel.



      I wrote a simple find/replace VBA macro in word to convert it to .csv, but the macro takes a long time to run through large sets of data.



      I'm looking for suggestions on a faster way to code this. Alternately, if there is another option for cleaning the data that would work better than Word and VBA, I'm willing to switch to it.



      Sub CleanText()


      Application.ScreenUpdating = False

      ' clean data for import to excel
      '
      Selection.Find.ClearFormatting
      Selection.Find.Replacement.ClearFormatting
      With Selection.Find
      .Text = "^p" & "^p"
      .Replacement.Text = "wvw"
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = False
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
      End With
      Selection.Find.Execute Replace:=wdReplaceAll

      Selection.Find.ClearFormatting
      Selection.Find.Replacement.ClearFormatting
      With Selection.Find
      .Text = "^p"
      .Replacement.Text = ","

      End With
      Selection.Find.Execute Replace:=wdReplaceAll

      Selection.Find.ClearFormatting
      Selection.Find.Replacement.ClearFormatting
      With Selection.Find
      .Text = "wvw"
      .Replacement.Text = "^p"
      .Forward = True

      End With
      Selection.Find.Execute Replace:=wdReplaceAll

      Selection.Find.ClearFormatting
      Selection.Find.Replacement.ClearFormatting
      With Selection.Find
      .Text = "$GPGGA" & "(*)" & "$GPRMC"
      .Replacement.Text = "$GPRMC"
      .MatchWildcards = True

      End With
      Selection.Find.Execute Replace:=wdReplaceAll

      Selection.Find.ClearFormatting
      Selection.Find.Replacement.ClearFormatting
      With Selection.Find
      .Text = "W" & "(*)" & "S"
      .Replacement.Text = "W,"
      End With
      Selection.Find.Execute Replace:=wdReplaceAll

      Selection.Find.ClearFormatting
      Selection.Find.Replacement.ClearFormatting
      With Selection.Find
      .Text = "V" & "(*)" & "S"
      .Replacement.Text = "V,,,,,"
      End With
      Selection.Find.Execute Replace:=wdReplaceAll

      Selection.Find.ClearFormatting
      Selection.Find.Replacement.ClearFormatting
      With Selection.Find
      .Text = "$GPRMC,"
      .Replacement.Text = ""
      End With
      Selection.Find.Execute Replace:=wdReplaceAll

      Application.ScreenUpdating = True

      End Sub









      share|improve this question















      I have a large amount of data from a hardware device that needs to be cleaned up so it can be analyzed in Excel.



      I wrote a simple find/replace VBA macro in word to convert it to .csv, but the macro takes a long time to run through large sets of data.



      I'm looking for suggestions on a faster way to code this. Alternately, if there is another option for cleaning the data that would work better than Word and VBA, I'm willing to switch to it.



      Sub CleanText()


      Application.ScreenUpdating = False

      ' clean data for import to excel
      '
      Selection.Find.ClearFormatting
      Selection.Find.Replacement.ClearFormatting
      With Selection.Find
      .Text = "^p" & "^p"
      .Replacement.Text = "wvw"
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = False
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
      End With
      Selection.Find.Execute Replace:=wdReplaceAll

      Selection.Find.ClearFormatting
      Selection.Find.Replacement.ClearFormatting
      With Selection.Find
      .Text = "^p"
      .Replacement.Text = ","

      End With
      Selection.Find.Execute Replace:=wdReplaceAll

      Selection.Find.ClearFormatting
      Selection.Find.Replacement.ClearFormatting
      With Selection.Find
      .Text = "wvw"
      .Replacement.Text = "^p"
      .Forward = True

      End With
      Selection.Find.Execute Replace:=wdReplaceAll

      Selection.Find.ClearFormatting
      Selection.Find.Replacement.ClearFormatting
      With Selection.Find
      .Text = "$GPGGA" & "(*)" & "$GPRMC"
      .Replacement.Text = "$GPRMC"
      .MatchWildcards = True

      End With
      Selection.Find.Execute Replace:=wdReplaceAll

      Selection.Find.ClearFormatting
      Selection.Find.Replacement.ClearFormatting
      With Selection.Find
      .Text = "W" & "(*)" & "S"
      .Replacement.Text = "W,"
      End With
      Selection.Find.Execute Replace:=wdReplaceAll

      Selection.Find.ClearFormatting
      Selection.Find.Replacement.ClearFormatting
      With Selection.Find
      .Text = "V" & "(*)" & "S"
      .Replacement.Text = "V,,,,,"
      End With
      Selection.Find.Execute Replace:=wdReplaceAll

      Selection.Find.ClearFormatting
      Selection.Find.Replacement.ClearFormatting
      With Selection.Find
      .Text = "$GPRMC,"
      .Replacement.Text = ""
      End With
      Selection.Find.Execute Replace:=wdReplaceAll

      Application.ScreenUpdating = True

      End Sub






      performance vba ms-word






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 17 '17 at 4:47

























      asked Nov 17 '17 at 4:22









      gkavet

      183




      183






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          You're doing a lot with .Selection. By default, that is going to be slow. Doing things behind the scenes is always faster. Either way, working with selection isn't the best way to go. Either pass the document to the sub or prompt the user. Is the selection a document, text, body, header, title, section? Be explicit.



          The way you use .Find makes me thing you're referring to a range, which can be any of those things. Let's take a look at the basic skeleton of your sub -




              With Selection
          .Find.ClearFormatting
          .Find.Replacement.ClearFormatting
          .Find
          .Find.Execute
          .Find.ClearFormatting
          .Find.Replacement.ClearFormatting
          .Find
          .Find.Execute
          .Find.ClearFormatting
          .Find.Replacement.ClearFormatting
          .Find
          .Find.Execute
          .Find.ClearFormatting
          .Find.Replacement.ClearFormatting
          .Find
          .Find.Execute
          .Find.ClearFormatting
          .Find.Replacement.ClearFormatting
          .Find
          .Find.Execute
          .Find.ClearFormatting
          .Find.Replacement.ClearFormatting
          .Find
          .Find.Execute
          .Find.ClearFormatting
          .Find.Replacement.ClearFormatting
          .Find
          .Find.Execute
          End With



          Yikes. You're doing the same thing 7 times. At worst that should be refactored. Something like this -



          Private Sub AlterRange(ByVal target As Range, ByVal findString As String, ByVal replaceString As String)
          With target
          .Find.ClearFormatting
          .Find.Replacement.ClearFormatting
          .Find
          .Text findString
          .Replacement replaceString
          .Find.Execute Replace:=wdReplaceAll
          End With
          End Sub


          Now something like this would work



          Dim target As Range
          Set target = Selection
          Dim findStrings(1 To 7) As String
          findStrings(1) = "^p^p"
          findStrings(2) = "^p"
          findStrings(3) = "wvw"
          findStrings(4) = "$GPGGA" & "(*)" & "$GPRMC"
          '...
          Dim replacestrings(1 To 7) As String
          replacestrings(1) = "wvw"
          replacestrings(2) = ","
          '...

          Dim i As Long
          For i = 1 To 7
          AlterRange target, findStrings(i), replacestrings(i)
          Next


          All of this is untested, but you get the idea.





          What you could do to speed it up is to create a variant (or whatever) to store the entire selection in and then do your finding and replacing in the variant, then place the variant back out to the sheet overwriting the selection.



          I don't know how all this would interact with your formatting, but it doesn't seem like you're keeping any formatting so it shouldn't be a problem.






          share|improve this answer





















            Your Answer





            StackExchange.ifUsing("editor", function () {
            return StackExchange.using("mathjaxEditing", function () {
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
            });
            });
            }, "mathjax-editing");

            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "196"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f180645%2flarge-find-replace-in-word-using-vba%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            You're doing a lot with .Selection. By default, that is going to be slow. Doing things behind the scenes is always faster. Either way, working with selection isn't the best way to go. Either pass the document to the sub or prompt the user. Is the selection a document, text, body, header, title, section? Be explicit.



            The way you use .Find makes me thing you're referring to a range, which can be any of those things. Let's take a look at the basic skeleton of your sub -




                With Selection
            .Find.ClearFormatting
            .Find.Replacement.ClearFormatting
            .Find
            .Find.Execute
            .Find.ClearFormatting
            .Find.Replacement.ClearFormatting
            .Find
            .Find.Execute
            .Find.ClearFormatting
            .Find.Replacement.ClearFormatting
            .Find
            .Find.Execute
            .Find.ClearFormatting
            .Find.Replacement.ClearFormatting
            .Find
            .Find.Execute
            .Find.ClearFormatting
            .Find.Replacement.ClearFormatting
            .Find
            .Find.Execute
            .Find.ClearFormatting
            .Find.Replacement.ClearFormatting
            .Find
            .Find.Execute
            .Find.ClearFormatting
            .Find.Replacement.ClearFormatting
            .Find
            .Find.Execute
            End With



            Yikes. You're doing the same thing 7 times. At worst that should be refactored. Something like this -



            Private Sub AlterRange(ByVal target As Range, ByVal findString As String, ByVal replaceString As String)
            With target
            .Find.ClearFormatting
            .Find.Replacement.ClearFormatting
            .Find
            .Text findString
            .Replacement replaceString
            .Find.Execute Replace:=wdReplaceAll
            End With
            End Sub


            Now something like this would work



            Dim target As Range
            Set target = Selection
            Dim findStrings(1 To 7) As String
            findStrings(1) = "^p^p"
            findStrings(2) = "^p"
            findStrings(3) = "wvw"
            findStrings(4) = "$GPGGA" & "(*)" & "$GPRMC"
            '...
            Dim replacestrings(1 To 7) As String
            replacestrings(1) = "wvw"
            replacestrings(2) = ","
            '...

            Dim i As Long
            For i = 1 To 7
            AlterRange target, findStrings(i), replacestrings(i)
            Next


            All of this is untested, but you get the idea.





            What you could do to speed it up is to create a variant (or whatever) to store the entire selection in and then do your finding and replacing in the variant, then place the variant back out to the sheet overwriting the selection.



            I don't know how all this would interact with your formatting, but it doesn't seem like you're keeping any formatting so it shouldn't be a problem.






            share|improve this answer

























              up vote
              0
              down vote













              You're doing a lot with .Selection. By default, that is going to be slow. Doing things behind the scenes is always faster. Either way, working with selection isn't the best way to go. Either pass the document to the sub or prompt the user. Is the selection a document, text, body, header, title, section? Be explicit.



              The way you use .Find makes me thing you're referring to a range, which can be any of those things. Let's take a look at the basic skeleton of your sub -




                  With Selection
              .Find.ClearFormatting
              .Find.Replacement.ClearFormatting
              .Find
              .Find.Execute
              .Find.ClearFormatting
              .Find.Replacement.ClearFormatting
              .Find
              .Find.Execute
              .Find.ClearFormatting
              .Find.Replacement.ClearFormatting
              .Find
              .Find.Execute
              .Find.ClearFormatting
              .Find.Replacement.ClearFormatting
              .Find
              .Find.Execute
              .Find.ClearFormatting
              .Find.Replacement.ClearFormatting
              .Find
              .Find.Execute
              .Find.ClearFormatting
              .Find.Replacement.ClearFormatting
              .Find
              .Find.Execute
              .Find.ClearFormatting
              .Find.Replacement.ClearFormatting
              .Find
              .Find.Execute
              End With



              Yikes. You're doing the same thing 7 times. At worst that should be refactored. Something like this -



              Private Sub AlterRange(ByVal target As Range, ByVal findString As String, ByVal replaceString As String)
              With target
              .Find.ClearFormatting
              .Find.Replacement.ClearFormatting
              .Find
              .Text findString
              .Replacement replaceString
              .Find.Execute Replace:=wdReplaceAll
              End With
              End Sub


              Now something like this would work



              Dim target As Range
              Set target = Selection
              Dim findStrings(1 To 7) As String
              findStrings(1) = "^p^p"
              findStrings(2) = "^p"
              findStrings(3) = "wvw"
              findStrings(4) = "$GPGGA" & "(*)" & "$GPRMC"
              '...
              Dim replacestrings(1 To 7) As String
              replacestrings(1) = "wvw"
              replacestrings(2) = ","
              '...

              Dim i As Long
              For i = 1 To 7
              AlterRange target, findStrings(i), replacestrings(i)
              Next


              All of this is untested, but you get the idea.





              What you could do to speed it up is to create a variant (or whatever) to store the entire selection in and then do your finding and replacing in the variant, then place the variant back out to the sheet overwriting the selection.



              I don't know how all this would interact with your formatting, but it doesn't seem like you're keeping any formatting so it shouldn't be a problem.






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                You're doing a lot with .Selection. By default, that is going to be slow. Doing things behind the scenes is always faster. Either way, working with selection isn't the best way to go. Either pass the document to the sub or prompt the user. Is the selection a document, text, body, header, title, section? Be explicit.



                The way you use .Find makes me thing you're referring to a range, which can be any of those things. Let's take a look at the basic skeleton of your sub -




                    With Selection
                .Find.ClearFormatting
                .Find.Replacement.ClearFormatting
                .Find
                .Find.Execute
                .Find.ClearFormatting
                .Find.Replacement.ClearFormatting
                .Find
                .Find.Execute
                .Find.ClearFormatting
                .Find.Replacement.ClearFormatting
                .Find
                .Find.Execute
                .Find.ClearFormatting
                .Find.Replacement.ClearFormatting
                .Find
                .Find.Execute
                .Find.ClearFormatting
                .Find.Replacement.ClearFormatting
                .Find
                .Find.Execute
                .Find.ClearFormatting
                .Find.Replacement.ClearFormatting
                .Find
                .Find.Execute
                .Find.ClearFormatting
                .Find.Replacement.ClearFormatting
                .Find
                .Find.Execute
                End With



                Yikes. You're doing the same thing 7 times. At worst that should be refactored. Something like this -



                Private Sub AlterRange(ByVal target As Range, ByVal findString As String, ByVal replaceString As String)
                With target
                .Find.ClearFormatting
                .Find.Replacement.ClearFormatting
                .Find
                .Text findString
                .Replacement replaceString
                .Find.Execute Replace:=wdReplaceAll
                End With
                End Sub


                Now something like this would work



                Dim target As Range
                Set target = Selection
                Dim findStrings(1 To 7) As String
                findStrings(1) = "^p^p"
                findStrings(2) = "^p"
                findStrings(3) = "wvw"
                findStrings(4) = "$GPGGA" & "(*)" & "$GPRMC"
                '...
                Dim replacestrings(1 To 7) As String
                replacestrings(1) = "wvw"
                replacestrings(2) = ","
                '...

                Dim i As Long
                For i = 1 To 7
                AlterRange target, findStrings(i), replacestrings(i)
                Next


                All of this is untested, but you get the idea.





                What you could do to speed it up is to create a variant (or whatever) to store the entire selection in and then do your finding and replacing in the variant, then place the variant back out to the sheet overwriting the selection.



                I don't know how all this would interact with your formatting, but it doesn't seem like you're keeping any formatting so it shouldn't be a problem.






                share|improve this answer












                You're doing a lot with .Selection. By default, that is going to be slow. Doing things behind the scenes is always faster. Either way, working with selection isn't the best way to go. Either pass the document to the sub or prompt the user. Is the selection a document, text, body, header, title, section? Be explicit.



                The way you use .Find makes me thing you're referring to a range, which can be any of those things. Let's take a look at the basic skeleton of your sub -




                    With Selection
                .Find.ClearFormatting
                .Find.Replacement.ClearFormatting
                .Find
                .Find.Execute
                .Find.ClearFormatting
                .Find.Replacement.ClearFormatting
                .Find
                .Find.Execute
                .Find.ClearFormatting
                .Find.Replacement.ClearFormatting
                .Find
                .Find.Execute
                .Find.ClearFormatting
                .Find.Replacement.ClearFormatting
                .Find
                .Find.Execute
                .Find.ClearFormatting
                .Find.Replacement.ClearFormatting
                .Find
                .Find.Execute
                .Find.ClearFormatting
                .Find.Replacement.ClearFormatting
                .Find
                .Find.Execute
                .Find.ClearFormatting
                .Find.Replacement.ClearFormatting
                .Find
                .Find.Execute
                End With



                Yikes. You're doing the same thing 7 times. At worst that should be refactored. Something like this -



                Private Sub AlterRange(ByVal target As Range, ByVal findString As String, ByVal replaceString As String)
                With target
                .Find.ClearFormatting
                .Find.Replacement.ClearFormatting
                .Find
                .Text findString
                .Replacement replaceString
                .Find.Execute Replace:=wdReplaceAll
                End With
                End Sub


                Now something like this would work



                Dim target As Range
                Set target = Selection
                Dim findStrings(1 To 7) As String
                findStrings(1) = "^p^p"
                findStrings(2) = "^p"
                findStrings(3) = "wvw"
                findStrings(4) = "$GPGGA" & "(*)" & "$GPRMC"
                '...
                Dim replacestrings(1 To 7) As String
                replacestrings(1) = "wvw"
                replacestrings(2) = ","
                '...

                Dim i As Long
                For i = 1 To 7
                AlterRange target, findStrings(i), replacestrings(i)
                Next


                All of this is untested, but you get the idea.





                What you could do to speed it up is to create a variant (or whatever) to store the entire selection in and then do your finding and replacing in the variant, then place the variant back out to the sheet overwriting the selection.



                I don't know how all this would interact with your formatting, but it doesn't seem like you're keeping any formatting so it shouldn't be a problem.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 20 at 23:45









                Raystafarian

                5,7841047




                5,7841047






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f180645%2flarge-find-replace-in-word-using-vba%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Mont Emei

                    Province de Neuquén

                    Journaliste