How do I convert this Excel macro for use in Word?Find specific text and delete three rows above itHow to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?How do you display code snippets in MS Word preserving format and syntax highlighting?How to avoid using Select in Excel VBAIs there a way to use the find function with changing, user inputted values in an excel macro?How to use Regular Expressions (Regex) in Microsoft Excel both in-cell and loopsUpdate MS Word fields based on contents of other fields within the documentRun-time Error '91': Excel 2011 for Mac VBAInsert line after last row of specific textWord VBA While Wend statement not workingCombined data from multiple sheets into one sheet

Any gotchas in buying second-hand sanitary ware?

New Site Design!

How can this shape perfectly cover a cube?

Why did the AvroCar fail to fly above 3 feet?

Fastest way from 10 to 1 with everyone in between

Opposite of "Concerto Grosso"?

Is it possible to have battery technology that can't be duplicated?

What is the color associated with lukewarm?

Must a CPU have a GPU if the motherboard provides a display port (when there isn't any separate video card)?

Why do the “Shtei HaLechem” not play a prominent part in the davenning for Shavuos?

ISP is not hashing the password I log in with online. Should I take any action?

Boss making me feel guilty for leaving the company at the end of my internship

Is pointing finger in meeting consider bad?

Can I get a photo of an Ancient Arrow?

Optimising matrix generation time

Jam with honey & without pectin has a saucy consistency always

Parallelized for loop in Bash

Lightning Web Component (LWC) not evaluating if:true from test

Arrows inside a commutative diagram using tikzcd

How to search for Android apps without ads?

Approach sick days in feedback meeting

Someone who is granted access to information but not expected to read it

Has JSON.serialize suppressApexObjectNulls ever worked?

The best in flight meal option for those suffering from reflux



How do I convert this Excel macro for use in Word?


Find specific text and delete three rows above itHow to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?How do you display code snippets in MS Word preserving format and syntax highlighting?How to avoid using Select in Excel VBAIs there a way to use the find function with changing, user inputted values in an excel macro?How to use Regular Expressions (Regex) in Microsoft Excel both in-cell and loopsUpdate MS Word fields based on contents of other fields within the documentRun-time Error '91': Excel 2011 for Mac VBAInsert line after last row of specific textWord VBA While Wend statement not workingCombined data from multiple sheets into one sheet






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have found a macro written for Excel that has the exact function that I need but I don't know how to convert it for use in Word - I'm fairly new to scripting and the only language/syntax that I'm familiar with is the Aspect scripting language that I've been learning from working with Procomm Plus. I found the Excel macro here:



Find specific text and delete three rows above it



Sub Delete()
Dim find As String: find = "TOT"
Dim rng As Range

Set rng = Sheets("Sheet1").Cells.find(What:=find, After:=Sheets("Sheet1").Cells(1, 1), LookIn:=xlValues, Lookat:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=True)

If Not rng Is Nothing Then
rng.EntireRow.Delete
rng.Offset(-1).EntireRow.Delete
rng.Offset(-2).EntireRow.Delete
rng.Offset(-3).EntireRow.Delete
End If

End Sub


I need the macro to look for the the text "% Invalid input detected at ‘^’ marker" and then delete it, as well as the two lines above that phrase:



Router#show environment all ;(let's call this "line -2")
^ ;(and this would be "line -1")
% Invalid input detected at ‘^’ marker ;(and "line 0")


This is the console output from a Cisco router (copy/pasted to Word) and the phrase "% Invalid input detected at ‘^’ marker" is always the same but the two lines above it can vary, depending on what Cisco command I have used that has not been recognised.



I think the solution is probably quite simple but I'm stuck!



I found another macro for Word that performs a similar function and - it looks for a key phrase and deletes the line containing that phrase but again, I'm not sure how to extend it to include the preceding two lines of text:



Sub InvalidInput()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "Invalid input detected"
While .Execute
oRng.Paragraphs(1).Range.Delete
Wend
End With
End Sub


Would anyone be able to suggest some edits that could solve my problem? Thank you very much in advance.










share|improve this question






























    0















    I have found a macro written for Excel that has the exact function that I need but I don't know how to convert it for use in Word - I'm fairly new to scripting and the only language/syntax that I'm familiar with is the Aspect scripting language that I've been learning from working with Procomm Plus. I found the Excel macro here:



    Find specific text and delete three rows above it



    Sub Delete()
    Dim find As String: find = "TOT"
    Dim rng As Range

    Set rng = Sheets("Sheet1").Cells.find(What:=find, After:=Sheets("Sheet1").Cells(1, 1), LookIn:=xlValues, Lookat:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=True)

    If Not rng Is Nothing Then
    rng.EntireRow.Delete
    rng.Offset(-1).EntireRow.Delete
    rng.Offset(-2).EntireRow.Delete
    rng.Offset(-3).EntireRow.Delete
    End If

    End Sub


    I need the macro to look for the the text "% Invalid input detected at ‘^’ marker" and then delete it, as well as the two lines above that phrase:



    Router#show environment all ;(let's call this "line -2")
    ^ ;(and this would be "line -1")
    % Invalid input detected at ‘^’ marker ;(and "line 0")


    This is the console output from a Cisco router (copy/pasted to Word) and the phrase "% Invalid input detected at ‘^’ marker" is always the same but the two lines above it can vary, depending on what Cisco command I have used that has not been recognised.



    I think the solution is probably quite simple but I'm stuck!



    I found another macro for Word that performs a similar function and - it looks for a key phrase and deletes the line containing that phrase but again, I'm not sure how to extend it to include the preceding two lines of text:



    Sub InvalidInput()
    Dim oRng As Word.Range
    Set oRng = ActiveDocument.Range
    With oRng.Find
    .Text = "Invalid input detected"
    While .Execute
    oRng.Paragraphs(1).Range.Delete
    Wend
    End With
    End Sub


    Would anyone be able to suggest some edits that could solve my problem? Thank you very much in advance.










    share|improve this question


























      0












      0








      0


      0






      I have found a macro written for Excel that has the exact function that I need but I don't know how to convert it for use in Word - I'm fairly new to scripting and the only language/syntax that I'm familiar with is the Aspect scripting language that I've been learning from working with Procomm Plus. I found the Excel macro here:



      Find specific text and delete three rows above it



      Sub Delete()
      Dim find As String: find = "TOT"
      Dim rng As Range

      Set rng = Sheets("Sheet1").Cells.find(What:=find, After:=Sheets("Sheet1").Cells(1, 1), LookIn:=xlValues, Lookat:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=True)

      If Not rng Is Nothing Then
      rng.EntireRow.Delete
      rng.Offset(-1).EntireRow.Delete
      rng.Offset(-2).EntireRow.Delete
      rng.Offset(-3).EntireRow.Delete
      End If

      End Sub


      I need the macro to look for the the text "% Invalid input detected at ‘^’ marker" and then delete it, as well as the two lines above that phrase:



      Router#show environment all ;(let's call this "line -2")
      ^ ;(and this would be "line -1")
      % Invalid input detected at ‘^’ marker ;(and "line 0")


      This is the console output from a Cisco router (copy/pasted to Word) and the phrase "% Invalid input detected at ‘^’ marker" is always the same but the two lines above it can vary, depending on what Cisco command I have used that has not been recognised.



      I think the solution is probably quite simple but I'm stuck!



      I found another macro for Word that performs a similar function and - it looks for a key phrase and deletes the line containing that phrase but again, I'm not sure how to extend it to include the preceding two lines of text:



      Sub InvalidInput()
      Dim oRng As Word.Range
      Set oRng = ActiveDocument.Range
      With oRng.Find
      .Text = "Invalid input detected"
      While .Execute
      oRng.Paragraphs(1).Range.Delete
      Wend
      End With
      End Sub


      Would anyone be able to suggest some edits that could solve my problem? Thank you very much in advance.










      share|improve this question
















      I have found a macro written for Excel that has the exact function that I need but I don't know how to convert it for use in Word - I'm fairly new to scripting and the only language/syntax that I'm familiar with is the Aspect scripting language that I've been learning from working with Procomm Plus. I found the Excel macro here:



      Find specific text and delete three rows above it



      Sub Delete()
      Dim find As String: find = "TOT"
      Dim rng As Range

      Set rng = Sheets("Sheet1").Cells.find(What:=find, After:=Sheets("Sheet1").Cells(1, 1), LookIn:=xlValues, Lookat:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=True)

      If Not rng Is Nothing Then
      rng.EntireRow.Delete
      rng.Offset(-1).EntireRow.Delete
      rng.Offset(-2).EntireRow.Delete
      rng.Offset(-3).EntireRow.Delete
      End If

      End Sub


      I need the macro to look for the the text "% Invalid input detected at ‘^’ marker" and then delete it, as well as the two lines above that phrase:



      Router#show environment all ;(let's call this "line -2")
      ^ ;(and this would be "line -1")
      % Invalid input detected at ‘^’ marker ;(and "line 0")


      This is the console output from a Cisco router (copy/pasted to Word) and the phrase "% Invalid input detected at ‘^’ marker" is always the same but the two lines above it can vary, depending on what Cisco command I have used that has not been recognised.



      I think the solution is probably quite simple but I'm stuck!



      I found another macro for Word that performs a similar function and - it looks for a key phrase and deletes the line containing that phrase but again, I'm not sure how to extend it to include the preceding two lines of text:



      Sub InvalidInput()
      Dim oRng As Word.Range
      Set oRng = ActiveDocument.Range
      With oRng.Find
      .Text = "Invalid input detected"
      While .Execute
      oRng.Paragraphs(1).Range.Delete
      Wend
      End With
      End Sub


      Would anyone be able to suggest some edits that could solve my problem? Thank you very much in advance.







      excel vba ms-word word-vba






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 25 at 9:43







      config_tea

















      asked Mar 25 at 0:48









      config_teaconfig_tea

      34




      34






















          2 Answers
          2






          active

          oldest

          votes


















          0














          Assuming your 'lines' are separate paragraphs, try:



          Sub Demo()
          Application.ScreenUpdating = False
          With ActiveDocument.Range
          With .Find
          .ClearFormatting
          .Replacement.ClearFormatting
          .Text = "[!^13]@^13[!^13]@^13% Invalid input detected at ‘^94’ marker^13"
          .Replacement.Text = ""
          .Forward = True
          .Wrap = wdFindStop
          .Format = False
          .MatchWildcards = True
          .Execute Replace:=wdReplaceAll
          End With
          End With
          Application.ScreenUpdating = True
          End Sub


          Otherwise, you'll have to provide a more meaningful description of what delineates your 'lines'.






          share|improve this answer

























          • Thank you, this is definitely working but with one small side effect - If I have a block of text above the section that gets deleted, the first word of the document gets deleted too.

            – config_tea
            Mar 25 at 10:04











          • Try the revised code.

            – macropod
            Mar 25 at 20:14











          • This is great, thank you!

            – config_tea
            Mar 26 at 8:03


















          0














          This is a longshot but have a go at this macro in Word ...



          Public Sub RemoveUnwantedParagraphs()
          Dim objParagraph As Paragraph, arrToRemove() As Long, lngIndex As Long
          Dim i As Long, x As Long, strSearchFor As String

          strSearchFor = "% Invalid input detected at '^' marker"

          lngIndex = -1

          For i = 1 To ThisDocument.Paragraphs.Count
          Set objParagraph = ThisDocument.Paragraphs(i)

          If Left(objParagraph.Range.Text, Len(strSearchFor)) = strSearchFor Then
          For x = 2 To 0 Step -1
          lngIndex = lngIndex + 1
          ReDim Preserve arrToRemove(lngIndex)
          arrToRemove(lngIndex) = i - x
          Next
          End If
          Next

          On Error GoTo ExitGracefully

          For i = UBound(arrToRemove) To 0 Step -1
          ThisDocument.Paragraphs(arrToRemove(i)).Range.Delete
          Next

          ExitGracefully:

          End Sub


          ... do yourself one favour though before you run it, BACKUP YOUR DOCUMENT!!!.



          I make no guarantees that it won't inadvertently stuff up the entire thing. I've done limited development in Word but that code above did work for me.



          The only thing to note is that if the text you're searching for is contained in the 1st or 2nd row, it may break. I figure that's not expected though so didn't cater for it.






          share|improve this answer

























            Your Answer






            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: "1"
            ;
            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',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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%2fstackoverflow.com%2fquestions%2f55330018%2fhow-do-i-convert-this-excel-macro-for-use-in-word%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Assuming your 'lines' are separate paragraphs, try:



            Sub Demo()
            Application.ScreenUpdating = False
            With ActiveDocument.Range
            With .Find
            .ClearFormatting
            .Replacement.ClearFormatting
            .Text = "[!^13]@^13[!^13]@^13% Invalid input detected at ‘^94’ marker^13"
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindStop
            .Format = False
            .MatchWildcards = True
            .Execute Replace:=wdReplaceAll
            End With
            End With
            Application.ScreenUpdating = True
            End Sub


            Otherwise, you'll have to provide a more meaningful description of what delineates your 'lines'.






            share|improve this answer

























            • Thank you, this is definitely working but with one small side effect - If I have a block of text above the section that gets deleted, the first word of the document gets deleted too.

              – config_tea
              Mar 25 at 10:04











            • Try the revised code.

              – macropod
              Mar 25 at 20:14











            • This is great, thank you!

              – config_tea
              Mar 26 at 8:03















            0














            Assuming your 'lines' are separate paragraphs, try:



            Sub Demo()
            Application.ScreenUpdating = False
            With ActiveDocument.Range
            With .Find
            .ClearFormatting
            .Replacement.ClearFormatting
            .Text = "[!^13]@^13[!^13]@^13% Invalid input detected at ‘^94’ marker^13"
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindStop
            .Format = False
            .MatchWildcards = True
            .Execute Replace:=wdReplaceAll
            End With
            End With
            Application.ScreenUpdating = True
            End Sub


            Otherwise, you'll have to provide a more meaningful description of what delineates your 'lines'.






            share|improve this answer

























            • Thank you, this is definitely working but with one small side effect - If I have a block of text above the section that gets deleted, the first word of the document gets deleted too.

              – config_tea
              Mar 25 at 10:04











            • Try the revised code.

              – macropod
              Mar 25 at 20:14











            • This is great, thank you!

              – config_tea
              Mar 26 at 8:03













            0












            0








            0







            Assuming your 'lines' are separate paragraphs, try:



            Sub Demo()
            Application.ScreenUpdating = False
            With ActiveDocument.Range
            With .Find
            .ClearFormatting
            .Replacement.ClearFormatting
            .Text = "[!^13]@^13[!^13]@^13% Invalid input detected at ‘^94’ marker^13"
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindStop
            .Format = False
            .MatchWildcards = True
            .Execute Replace:=wdReplaceAll
            End With
            End With
            Application.ScreenUpdating = True
            End Sub


            Otherwise, you'll have to provide a more meaningful description of what delineates your 'lines'.






            share|improve this answer















            Assuming your 'lines' are separate paragraphs, try:



            Sub Demo()
            Application.ScreenUpdating = False
            With ActiveDocument.Range
            With .Find
            .ClearFormatting
            .Replacement.ClearFormatting
            .Text = "[!^13]@^13[!^13]@^13% Invalid input detected at ‘^94’ marker^13"
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindStop
            .Format = False
            .MatchWildcards = True
            .Execute Replace:=wdReplaceAll
            End With
            End With
            Application.ScreenUpdating = True
            End Sub


            Otherwise, you'll have to provide a more meaningful description of what delineates your 'lines'.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 25 at 20:14

























            answered Mar 25 at 6:26









            macropodmacropod

            3,6952312




            3,6952312












            • Thank you, this is definitely working but with one small side effect - If I have a block of text above the section that gets deleted, the first word of the document gets deleted too.

              – config_tea
              Mar 25 at 10:04











            • Try the revised code.

              – macropod
              Mar 25 at 20:14











            • This is great, thank you!

              – config_tea
              Mar 26 at 8:03

















            • Thank you, this is definitely working but with one small side effect - If I have a block of text above the section that gets deleted, the first word of the document gets deleted too.

              – config_tea
              Mar 25 at 10:04











            • Try the revised code.

              – macropod
              Mar 25 at 20:14











            • This is great, thank you!

              – config_tea
              Mar 26 at 8:03
















            Thank you, this is definitely working but with one small side effect - If I have a block of text above the section that gets deleted, the first word of the document gets deleted too.

            – config_tea
            Mar 25 at 10:04





            Thank you, this is definitely working but with one small side effect - If I have a block of text above the section that gets deleted, the first word of the document gets deleted too.

            – config_tea
            Mar 25 at 10:04













            Try the revised code.

            – macropod
            Mar 25 at 20:14





            Try the revised code.

            – macropod
            Mar 25 at 20:14













            This is great, thank you!

            – config_tea
            Mar 26 at 8:03





            This is great, thank you!

            – config_tea
            Mar 26 at 8:03













            0














            This is a longshot but have a go at this macro in Word ...



            Public Sub RemoveUnwantedParagraphs()
            Dim objParagraph As Paragraph, arrToRemove() As Long, lngIndex As Long
            Dim i As Long, x As Long, strSearchFor As String

            strSearchFor = "% Invalid input detected at '^' marker"

            lngIndex = -1

            For i = 1 To ThisDocument.Paragraphs.Count
            Set objParagraph = ThisDocument.Paragraphs(i)

            If Left(objParagraph.Range.Text, Len(strSearchFor)) = strSearchFor Then
            For x = 2 To 0 Step -1
            lngIndex = lngIndex + 1
            ReDim Preserve arrToRemove(lngIndex)
            arrToRemove(lngIndex) = i - x
            Next
            End If
            Next

            On Error GoTo ExitGracefully

            For i = UBound(arrToRemove) To 0 Step -1
            ThisDocument.Paragraphs(arrToRemove(i)).Range.Delete
            Next

            ExitGracefully:

            End Sub


            ... do yourself one favour though before you run it, BACKUP YOUR DOCUMENT!!!.



            I make no guarantees that it won't inadvertently stuff up the entire thing. I've done limited development in Word but that code above did work for me.



            The only thing to note is that if the text you're searching for is contained in the 1st or 2nd row, it may break. I figure that's not expected though so didn't cater for it.






            share|improve this answer





























              0














              This is a longshot but have a go at this macro in Word ...



              Public Sub RemoveUnwantedParagraphs()
              Dim objParagraph As Paragraph, arrToRemove() As Long, lngIndex As Long
              Dim i As Long, x As Long, strSearchFor As String

              strSearchFor = "% Invalid input detected at '^' marker"

              lngIndex = -1

              For i = 1 To ThisDocument.Paragraphs.Count
              Set objParagraph = ThisDocument.Paragraphs(i)

              If Left(objParagraph.Range.Text, Len(strSearchFor)) = strSearchFor Then
              For x = 2 To 0 Step -1
              lngIndex = lngIndex + 1
              ReDim Preserve arrToRemove(lngIndex)
              arrToRemove(lngIndex) = i - x
              Next
              End If
              Next

              On Error GoTo ExitGracefully

              For i = UBound(arrToRemove) To 0 Step -1
              ThisDocument.Paragraphs(arrToRemove(i)).Range.Delete
              Next

              ExitGracefully:

              End Sub


              ... do yourself one favour though before you run it, BACKUP YOUR DOCUMENT!!!.



              I make no guarantees that it won't inadvertently stuff up the entire thing. I've done limited development in Word but that code above did work for me.



              The only thing to note is that if the text you're searching for is contained in the 1st or 2nd row, it may break. I figure that's not expected though so didn't cater for it.






              share|improve this answer



























                0












                0








                0







                This is a longshot but have a go at this macro in Word ...



                Public Sub RemoveUnwantedParagraphs()
                Dim objParagraph As Paragraph, arrToRemove() As Long, lngIndex As Long
                Dim i As Long, x As Long, strSearchFor As String

                strSearchFor = "% Invalid input detected at '^' marker"

                lngIndex = -1

                For i = 1 To ThisDocument.Paragraphs.Count
                Set objParagraph = ThisDocument.Paragraphs(i)

                If Left(objParagraph.Range.Text, Len(strSearchFor)) = strSearchFor Then
                For x = 2 To 0 Step -1
                lngIndex = lngIndex + 1
                ReDim Preserve arrToRemove(lngIndex)
                arrToRemove(lngIndex) = i - x
                Next
                End If
                Next

                On Error GoTo ExitGracefully

                For i = UBound(arrToRemove) To 0 Step -1
                ThisDocument.Paragraphs(arrToRemove(i)).Range.Delete
                Next

                ExitGracefully:

                End Sub


                ... do yourself one favour though before you run it, BACKUP YOUR DOCUMENT!!!.



                I make no guarantees that it won't inadvertently stuff up the entire thing. I've done limited development in Word but that code above did work for me.



                The only thing to note is that if the text you're searching for is contained in the 1st or 2nd row, it may break. I figure that's not expected though so didn't cater for it.






                share|improve this answer















                This is a longshot but have a go at this macro in Word ...



                Public Sub RemoveUnwantedParagraphs()
                Dim objParagraph As Paragraph, arrToRemove() As Long, lngIndex As Long
                Dim i As Long, x As Long, strSearchFor As String

                strSearchFor = "% Invalid input detected at '^' marker"

                lngIndex = -1

                For i = 1 To ThisDocument.Paragraphs.Count
                Set objParagraph = ThisDocument.Paragraphs(i)

                If Left(objParagraph.Range.Text, Len(strSearchFor)) = strSearchFor Then
                For x = 2 To 0 Step -1
                lngIndex = lngIndex + 1
                ReDim Preserve arrToRemove(lngIndex)
                arrToRemove(lngIndex) = i - x
                Next
                End If
                Next

                On Error GoTo ExitGracefully

                For i = UBound(arrToRemove) To 0 Step -1
                ThisDocument.Paragraphs(arrToRemove(i)).Range.Delete
                Next

                ExitGracefully:

                End Sub


                ... do yourself one favour though before you run it, BACKUP YOUR DOCUMENT!!!.



                I make no guarantees that it won't inadvertently stuff up the entire thing. I've done limited development in Word but that code above did work for me.



                The only thing to note is that if the text you're searching for is contained in the 1st or 2nd row, it may break. I figure that's not expected though so didn't cater for it.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 25 at 4:08

























                answered Mar 25 at 3:43









                SkinSkin

                2,1182515




                2,1182515



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55330018%2fhow-do-i-convert-this-excel-macro-for-use-in-word%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

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript