none
Macro to move text to a certain position? RRS feed

  • Question

  • I review a lot of legal documents and just discussed a macro that I've customized to highlight certain words different colors for easy scanning. This is pretty huge for me.

    I also type up a lot of notes/agenda and have a system for identifying items as a question, a follow-up, or an issue. I applied the same principles of the highlight for this as a search/replace function and it is going to save me a ton of time.

    But now I'm feeling greedy.

    Anyone have any idea if there would be a way to create a macro to move text into another section on a word document? For example, when I type my notes, I do it by certain categories, let's say there are 5 categories. After I review the documents, I run my macro and it highlights what I have labeled as a question, follow-up or issue. Now I'm wondering if I could run a macro to take all the things that have been labeled as questions and regroup them somewhere else on the document, same with the follow-ups, etc.

    This would save me an unquantifiable amount of time through the year, but I feel like it would be difficult to set up.

    If it matters, when I type my notes, they're in bullet formatting.

    The way I currently go through my process is that I look at various reports and type notes associated with those reports.

    I started using a symbol as shorthand before typing the note to identify it in one of the three aforementioned categories: (i) Question; (ii) Follow-up; (iii) Issue (or Exclusion).

    The way I have done this is that if the item needs to be follow-up on, I simply type: '[[' (without quotes). For questions, I type: '[' and exclusions: '{'.

    Then I used to go through, do a find and replace with highlight to replace those symbols with the lead-in of QUESTION: FOLLOW-UP: or EXCLUSION: with various colors.

    Now with my new macro, I don't need to do the find and replace, so it saves a good bit of time.

    However, I thought it would be great if I could have the first page of my Notes template automatically aggregate a copy of every follow-up, exclusion or question. 

    Here is my current highlight/replace macro that I've been using:

    Quote:

    Sub Highlight_Knowledge_Green()
    '
    ' Highlight_Knowledge_Green Macro
    '
    'Sub ReplaceList()
    Dim vFindText As Variant
    Dim vReplText As Variant
    Dim i As Long

    'highlight knowledge
    Options.DefaultHighlightColorIndex = wdGreen
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting

    vFindText = Array("knowledge", "knowledgeable")
    vReplText = "^&"
    With Selection.Find
    .Forward = True
    .Wrap = wdFindContinue
    .MatchWholeWord = True
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Format = True
    .MatchCase = False

    For i = LBound(vFindText) To UBound(vFindText)
    .Text = vFindText(i)
    .Replacement.Text = vReplText
    .Replacement.Highlight = True
    .Execute Replace:=wdReplaceAll
    Next i
    End With

    'Highlight Material
    Options.DefaultHighlightColorIndex = wdYellow

    vFindText = Array("material", "material adverse effect", "materially")
    vReplText = "^&"
    With Selection.Find
    .Forward = True
    .Wrap = wdFindContinue

    For i = LBound(vFindText) To UBound(vFindText)
    .Text = vFindText(i)
    .Replacement.Text = vReplText
    .Replacement.Highlight = True
    .Execute Replace:=wdReplaceAll
    Next i
    End With

    'Highlight Material Customer/Material Supplier/Material Contract
    Options.DefaultHighlightColorIndex = wdRed

    vFindText = Array("material customer", "material supplier", "material contract")
    vReplText = "^&"
    With Selection.Find
    .Forward = True
    .Wrap = wdFindContinue

    For i = LBound(vFindText) To UBound(vFindText)
    .Text = vFindText(i)
    .Replacement.Text = vReplText
    .Replacement.Highlight = True
    .Execute Replace:=wdReplaceAll
    Next i
    End With

    'Highlight Threat
    Options.DefaultHighlightColorIndex = wdPink

    vFindText = Array("threat", "threatened", "threatening")
    vReplText = "^&"
    With Selection.Find
    .Forward = True
    .Wrap = wdFindContinue

    For i = LBound(vFindText) To UBound(vFindText)
    .Text = vFindText(i)
    .Replacement.Text = vReplText
    .Replacement.Highlight = True
    .Execute Replace:=wdReplaceAll
    Next i
    End With

    End Sub


    Attached is a sample template I just put together. You'll see under Legal and Financial review there is an example for one of each the three categories that I would ideally like to:
    1. Hit my macro, have it convert into question/follow/exclusion
    2. Hit the second macro to have it move those lines into one of the three categories on the top page


    • Moved by Steve Fan Tuesday, December 12, 2017 1:50 AM relocate
    Friday, December 8, 2017 4:38 PM

All replies

  • So I've waiting for my account to be verified before I can post a link, sorry.
    Friday, December 8, 2017 4:42 PM
  • Have you considered using Word's comment feature? These can be printed (perhaps to a pdf) separately.

    Do you want to move these or copy them?


    Charles Kenyon Madison, WI



    Sunday, December 10, 2017 5:30 PM
  • Hi,

    Welcome to the Microsoft Office for IT Professionals Word forum. This forum focuses more on non-programming questions related to Microsoft Word. Since your request is more related to macro, I'll move it to the dedicated Word for Developers forum:

    https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=worddev

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    Regards,

    Steve Fan


    Please remember to mark the replies as answers if they helped.
    If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Monday, December 11, 2017 2:06 AM
  • FWIW, your highlight macro could be reduced to:

    Sub Highlight_Terms()
    Dim vFindText As Variant, i As Long
    With ActiveDocument.Range.Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Forward = True
      .Wrap = wdFindContinue
      .MatchWholeWord = True
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
      .Format = True
      .MatchCase = False
      .Replacement.Text = "^&"
      .Replacement.Highlight = True
      
      'highlight knowledge
      Options.DefaultHighlightColorIndex = wdGreen
      vFindText = Array("knowledge", "knowledgeable")
      For i = LBound(vFindText) To UBound(vFindText)
        .Text = vFindText(i)
        .Execute Replace:=wdReplaceAll
      Next i
      
      'Highlight Material
      Options.DefaultHighlightColorIndex = wdYellow
      vFindText = Array("material", "material adverse effect", "materially")
      For i = LBound(vFindText) To UBound(vFindText)
        .Text = vFindText(i)
        .Execute Replace:=wdReplaceAll
      Next i
      
      'Highlight Material Customer/Material Supplier/Material Contract
      Options.DefaultHighlightColorIndex = wdRed
      vFindText = Array("material customer", "material supplier", "material contract")
      For i = LBound(vFindText) To UBound(vFindText)
        .Text = vFindText(i)
        .Execute Replace:=wdReplaceAll
      Next i
      
      'Highlight Threat
      Options.DefaultHighlightColorIndex = wdPink
      vFindText = Array("threat", "threatened", "threatening")
      For i = LBound(vFindText) To UBound(vFindText)
        .Text = vFindText(i)
        .Execute Replace:=wdReplaceAll
      Next i
    End With
    End Sub


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Monday, December 11, 2017 5:40 AM
  • Hi Charles

    Thanks for the response and sorry for the delay.  The comment feature does not do want I am looking for, but thanks for the recommendation.

    I want to copy and move these to another section within the same document.  So essentially on the first page I'll have a header section with three different categories, then on subsequent pages I'll have all the my notes typed up, run the macro, and it will copy and move the appropriate lines into their respective sections on the top page.

    Does this seem possible?

    Tuesday, December 12, 2017 9:16 PM
  • Thanks!  I can't take credit, I pulled the macro from another post and just updated it.  "Coding" is not my strong suit.
    Tuesday, December 12, 2017 9:16 PM
  • Hello,

    i suggest you upload your sample file into OneDrive and paste the link here.

    You could use the following code to find highlighted text and copy the paragrah. Then you could paste the range to section 1.

     Set myRng = ActiveDocument.Sections(2).Range
        With myRng.Find
            .ClearFormatting
            .Highlight = True
            While .Execute(Forward:=True, Format:=True)
                Debug.Print myRng.Paragraphs(1).Range.Text
                myRng.Paragraphs(1).Range.Copy
                'myRng.HighlightColorIndex = wdNoHighlight
            Wend
        End With

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 13, 2017 7:09 AM
    Moderator
  • While it's easy to say "copy and move the appropriate lines into their respective sections on the top page', doing so in code is far from being a trivial undertaking. You will need to explain how the notes relate to different parts of the document in a way a macro could recognise. For example, do both use the same headings & heading Styles? If not, you'll also need to explain how a macro would recognise where one note ends and another begins.

    Regardless, you seem to be creating work for yourself (and whoever else you want to do the coding). Why not simply put the notes where you want them from the outset?


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Wednesday, December 13, 2017 7:33 AM
  • Hi Paul

    Understood about the undertaking required here.  I do not currently separate headlines by Styles but could certainly work that into my template.  Agreed that there needs to be some differentation for the macro to recognize stard and end point.

    As to your question on why not put the notes there from the outset - this defeats the purpose because I am going through hundreds of pages of documents with various categories.  I want the questions/issues per category but then also aggregated.

    Does this seem impossible?

    Monday, December 18, 2017 9:00 PM
  • No, it's not impossible. As I already said, though:
    doing so in code is far from being a trivial undertaking


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Monday, December 18, 2017 11:51 PM