none
Help with looping a macro, or a workaround RRS feed

  • Question

  • I am trying to edit a document containing exported closed captions from a Youtube video I uploaded. What I am trying to do is delete a line number and time stamp about 1000 x in a row. Sample text is pasted in below. There is a pattern to the text that repeats every 4 lines. I just want to delete lines 1, 2, and 4.

    I have long known about macros, but have zero experience using them, or any type of coding for that matter. However, I was able to record a macro that does what I would like it to do, and that really piqued my interest. The trouble I have run into is that in order to clean up the whole document, I have to click a mouse button every time I want to run the macro. Secondly, for some reason after so many clicks, the cursor will end up in a different place than where it was when I recorded the macro, causing the pattern to go askew.

    I've searched the forums on here and learned about looping, but I wasn't able to figure out how to loop my specific macro. I also saw a response from someone who suggested a wildcard find/replace as a solution to a similar inquiry to mine, however I was not able to translate that to my problem. This led me to want to make my own thread, and pose the question of whether a macro is even what I need, or if there is some other workaround to achieve this simple edit. 


    Here is the macro I recorded using keystrokes:

    Sub Macro4()
    '
    ' Macro4 Macro
    '
    '
        Selection.MoveDown Unit:=wdLine, Count:=2, Extend:=wdExtend
        Selection.TypeBackspace
        Selection.MoveDown Unit:=wdLine, Count:=2
        Selection.TypeBackspace
        L
    End Sub

    Here is a sample of the text I am working with: 

    15
    00:00:58,460 --> 00:01:06,600
    so I had an opportunity to review 16 and

    16
    00:01:03,690 --> 00:01:15,869
    14 I haven't really read over the

    17
    00:01:06,600 --> 00:01:26,390
    subdivision agreement but to start I I

    18
    00:01:15,869 --> 00:01:26,390
    took a few notes yeah just one more yeah

    Monday, May 7, 2018 4:52 PM

All replies

  • From what you've described, you should be able to achieve the desired result with a wildcard Find/Replace, where:

    Find = ^13[0-9]@^13[0-9]@:[0-9]@*^13(*^13)*^13
    Replace = ^p\1

    No macros required, though you could record the above as a macro if you're doing this often.

    Note: It's not apparent from your sample what lines constitute 1, 2 & 4, so I've had to guess.


    Cheers
    Paul Edstein
    [MS MVP - Word]



    Monday, May 7, 2018 11:16 PM
  • Thank you for the help. Sorry my sample wasn't clear, here is a little more detail. Also with the 'blank' line, my goal would be to delete that line so that I end up with a transcript with no line breaks. At this point I would happily settle for deletion of the sequential numbers and time stamp.  

    Line 1 = a sequentially ordered number

    Line 2 = timestamp

    Line 3 = the text I want to keep

    Line 4 = Blank 


    "Here is a sample of the text I am working with: (With line numbers)"

    1)15
    2) 00:00:58,460 --> 00:01:06,600
    3) so I had an opportunity to review 16 and
    4)
    1)16

    2)00:01:03,690 --> 00:01:15,869

    3) 14 I haven't really read over the
    4) 
    1) 17
    2) 00:01:06,600 --> 00:01:26,390
    3) subdivision agreement but to start I I
    4)
    1) 18
    2) 00:01:15,869 --> 00:01:26,390
    3) took a few notes yeah just one more yeah

    4) 

    Tuesday, May 8, 2018 4:12 PM
  • If the data are as you've described, simply insert an empty paragraph before the first entry, then use a wildcard Find/Replace, where:
    Find = ^13[0-9]@^13[0-9]@:[0-9]*^13
    Replace = nothing

    That will delete the unwanted content in paragraph order 4,1,2, leaving just 3s and a final 4 (which you can delete manually) behind.

    Again, no macros required, though you could record the process as a macro if you're doing this often.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Wednesday, May 9, 2018 4:20 AM
  • Tao Zhou: The question is about Word, not Excel, and it's not possible to attach files here. Besides which, there is sufficient explanation, IMHO.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Wednesday, May 9, 2018 8:20 AM
  • Hi macropod,

    Thanks for pointing out, I will delete my prevous post.

    Best Regards,

    Tao Zhou


    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, May 9, 2018 8:24 AM