View Single Post
 
Old 04-17-2016, 05:40 PM
feenyman99 feenyman99 is offline Windows 10 Office 2013
Novice
 
Join Date: Apr 2016
Posts: 1
feenyman99 is on a distinguished road
Default Delete Text from Insertion Point to Found Text

Hi. Rookie here...

I have a LARGE text document that is actually the result of executing a DOS "dir /s" command and outputting it to a text file.

This file contains the following pattern repeated MANY times...
Directory of <directory name>
... <list of files>...
<# of files> File(s) <# of bytes> bytes
I want to create a Macro - or VBA code - that deletes the list of files, for EACH of the above blocks, and leaves me with the following...
Directory of <directory name> <# of bytes> bytes
Directory of <directory name> <# of bytes> bytes
...
Directory of <directory name> <# of bytes> bytes

This way I have a list of just the directory names and their sizes.

I imagine the following steps in my Macro:
1) Go to the next occurrence of "Directory of"
2) Go to the End of line
3) Delete from current location to the next occurrence of "File(s)"
4) Loop back to Step 1
I have tried recording a Macro to do this, but I get stuck at Step 3 above.

Can I do this with a Macro? If not, can someone post a VBA snippet that will do the job, if it's not too complicated?

If I should move this post to the VBA part of this forum, I'm happy to do so, but I was hoping I could get away with recording a Macro.

Thx,
feenyman99
Reply With Quote