Community
    • Login

    Issue with creating macro to search a phrese within script and copy all the results into new sheet

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 4 Posters 390 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Ohad IlanO
      Ohad Ilan
      last edited by

      Hi,
      I’m trying to record macro:

      1. Ctrl+F and search for a specific phrase within the current document
      2. Copy all the results from the Find window into new tab
      3. Search for a different phrase in the original document
      4. Copy all the results from find window into a new tab (different from the tab in step2)

      When running the Macro it is copping to the 2 tabs the last thing that was copied and not the search results.
      Can someone help me to solve this issue?

      This is the macro I recorded:
      <Macros>
      <Macro name=“Wrapper” Ctrl=“no” Alt=“no” Shift=“no” Key=“0”>
      <Action type=“3” message=“1700” wParam=“0” lParam=“0” sParam=“” />
      <Action type=“3” message=“1601” wParam=“0” lParam=“0” sParam=“UpdateLoginInfo” />
      <Action type=“3” message=“1625” wParam=“0” lParam=“0” sParam=“” />
      <Action type=“3” message=“1702” wParam=“0” lParam=“0” sParam=“” />
      <Action type=“3” message=“1701” wParam=“0” lParam=“1641” sParam=“” />
      <Action type=“0” message=“2422” wParam=“0” lParam=“0” sParam=“” />
      <Action type=“0” message=“2325” wParam=“0” lParam=“0” sParam=“” />
      <Action type=“2” message=“0” wParam=“41001” lParam=“0” sParam=“” />
      <Action type=“0” message=“2179” wParam=“0” lParam=“0” sParam=“” />
      <Action type=“0” message=“2422” wParam=“0” lParam=“0” sParam=“” />
      <Action type=“0” message=“2325” wParam=“0” lParam=“0” sParam=“” />
      <Action type=“3” message=“1700” wParam=“0” lParam=“0” sParam=“” />
      <Action type=“3” message=“1601” wParam=“0” lParam=“0” sParam=“Create args event” />
      <Action type=“3” message=“1625” wParam=“0” lParam=“0” sParam=“” />
      <Action type=“3” message=“1702” wParam=“0” lParam=“0” sParam=“” />
      <Action type=“3” message=“1701” wParam=“0” lParam=“1641” sParam=“” />
      <Action type=“0” message=“2422” wParam=“0” lParam=“0” sParam=“” />
      <Action type=“0” message=“2325” wParam=“0” lParam=“0” sParam=“” />
      <Action type=“2” message=“0” wParam=“41001” lParam=“0” sParam=“” />
      <Action type=“0” message=“2179” wParam=“0” lParam=“0” sParam=“” />
      </Macro>

      Alan KilbornA PeterJonesP 2 Replies Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Ohad Ilan
        last edited by

        @Ohad-Ilan

        I think when you say “Find window” you really mean the Find-result window, so the following is based upon that assumption.

        Actions involving the Find-result window are not macro-recordable so I think your idea is basically dead-in-the-water right there.

        If you are interested in a scripted solution, something could likely be done. There is some discussion of accessing the Find-result window’s data via scripting in this thread: https://community.notepad-plus-plus.org/topic/18524/save-found-files/

        1 Reply Last reply Reply Quote 2
        • PeterJonesP
          PeterJones @Ohad Ilan
          last edited by

          @Ohad-Ilan ,

          In light of what @Alan-Kilborn mentioned (find-results not being macro-accessible), if what you are calling the "new tab"s are truly new, empty tabs, I might take a different direction:

          1. copy original file to two new files, new1 and new2
          2. open new1; delete any lines that do not match phrase 1; save
          3. open new2; delete any lines that do not match phrase 2; save

          If I were to do this in a programming language (for example, by using the PythonScript plugin to run Python code on the files open in Notepad++), I would probably just run through the original file once rather than twice, using the logic “if this section matches phrase1 then copy to new1; if it matches phrase2 then copy to new2” – noting that nothing needs happen with “this section” if it doesn’t match either

          1 Reply Last reply Reply Quote 3
          • guy038G
            guy038
            last edited by guy038

            Hello, @ohad-ilan, @peterjones and All,

            Could you give a try to the following macro :

                    <Macro name="Wrapper" Ctrl="no" Alt="no" Shift="no" Key="0">
                        <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />                  <!-- Initialization SEARCH process         -->
                        <Action type="3" message="1601" wParam="0" lParam="0" sParam="UpdateLoginInfo" />   <!-- SEARCH "UpdateLoginInfo"              -->
                        <Action type="3" message="1625" wParam="0" lParam="0" sParam="" />                  <!-- NORMAL Search mode                    -->
                        <Action type="3" message="1702" wParam="0" lParam="790" sParam="" />                <!-- Down + Wrap + Mark + Purge + Case     -->
                        <Action type="3" message="1701" wParam="0" lParam="1615" sParam="" />               <!-- Mark All, in CURRENT file             -->
            
                        <Action type="2" message="0" wParam="43019" lParam="0" sParam="" />                 <!-- Copy BOOKMARKED Lines                 -->
            
                        <Action type="2" message="0" wParam="41001" lParam="0" sParam="" />                 <!-- Open a NEW file                       -->
                        <Action type="0" message="2179" wParam="0" lParam="0" sParam="" />                  <!-- PASTE the BOOKMARKED Lines            -->
            
                        <Action type="2" message="0" wParam="44096" lParam="0" sParam="" />                 <!-- Move to PREVIOUS tab ( File to SCAN ) -->
            
                        <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />                  <!-- Initialization SEARCH process         -->
                        <Action type="3" message="1601" wParam="0" lParam="0" sParam="Create args event" /> <!-- SEARCH "Create args event"            -->
                        <Action type="3" message="1625" wParam="0" lParam="0" sParam="" />                  <!-- NORMAL Search mode                    -->
                        <Action type="3" message="1702" wParam="0" lParam="790" sParam="" />                <!-- Down + Wrap + Mark + Purge + Case     -->
                        <Action type="3" message="1701" wParam="0" lParam="1615" sParam="" />               <!-- Mark All, in CURRENT file             -->
            
                        <Action type="2" message="0" wParam="43019" lParam="0" sParam="" />                 <!-- Copy BOOKMARKED Lines                 -->
                                                                                                            
                        <Action type="2" message="0" wParam="41001" lParam="0" sParam="" />                 <!-- Open an other NEW file                -->
                        <Action type="0" message="2179" wParam="0" lParam="0" sParam="" />                  <!-- PASTE the BOOKMARKED Lines            -->
            
                        <Action type="2" message="0" wParam="44096" lParam="0" sParam="" />                 <!-- Move to PREVIOUS tab ( New# File )    -->
                        <Action type="2" message="0" wParam="44096" lParam="0" sParam="" />                 <!-- Move to PREVIOUS tab ( File to SCAN ) -->
            
                        <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />                  <!-- Initialization SEARCH process         -->
                        <Action type="3" message="1601" wParam="0" lParam="0" sParam="" />                  <!-- SEARCH ""                             -->
                        <Action type="3" message="1625" wParam="0" lParam="0" sParam="" />                  <!-- NORMAL Search mode                    -->
                        <Action type="3" message="1702" wParam="0" lParam="16" sParam="" />                 <!-- 'Bookmark line' option                -->
                        <Action type="3" message="1701" wParam="0" lParam="1633" sParam="" />               <!-- CLEAR ALL marks, ( in File to SCAN )  -->
                    </Macro>
            

            Just tried it… It works fine ;-))

            Cheers,

            guy038

            Alan KilbornA 1 Reply Last reply Reply Quote 1
            • Alan KilbornA
              Alan Kilborn @guy038
              last edited by

              @guy038

              Nice solution that really looked at solving the OP’s problem, rather than (like me) focusing on “Copy all the results from the Find window” not being macro-recordable.

              1 Reply Last reply Reply Quote 1
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors