• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

7. Macro Hacks > 66. Hack Documents with For Each Loops

Hack Documents with For Each Loops

When you need a quick and dirty solution, you don’t always have time to find the best tool for the job. This hack introduces you to the Swiss Army Knife of VBA programming.

In the Unix world, a handy utility program called sed has been doing the dirty work of editing text files for more than 30 years. Other programs and languages have come along that can do the same thing sed does (and more), but thousands of users still fire up sed every single day. Why? Because sed reads and edits text files the same way people do: line by line; so it’s easy for people to “tell” sed what to do. It’s not the fastest, and it’s not the prettiest, but it’s hard to beat for automating rote tasks. A technique for writing macros in VBA shares that same trait of “thinking” the way people do, but about Word documents. It’s a For Each loop, and you should consider it your tool of first resort for quick and dirty solutions to everyday problems.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint