Hi all,
I'm an experienced programmer, but I'm a complete newbie in the realm of VBA. I've got a problem that I can't seem to answer with my combination of books/google/help files, and I searched here and couldn't find an answer either. I'm writing a macro to parse through an RTF file making formatting changes on certain text selections. I'd like to begin at the top, find a hard-coded key word, perform some Selection.Style and Selection.Paragraphs operations, and then move on to the next instance of the keyword. I can do all of this, but I don't know the proper way to handle loop control. Currently I just have a dummy Do/While loop (more or less as proof of concept.) My pseudocode solution looks like this:
Currently, instead of "Do While NOT END OF FILE", I have "DO WHILE lcv < 500" and then I increment lcv (loop control variable) each time through the loop.
Obviously, the macro is more complicated than that (or else I'd just use the replace all and skip the macro altogether), but that's the top-level overview. My problem is that I don't know how to use EOF in VBA. The actual EOF function seems to require a file number which requires opening a file in the macro, which just doesn't work. I'd like to either break out of the loop at the end of file, or count the number of keywords and use that as my lcv.
This should be relatively simple, but I've failed at finding a fix in the documentation anywhere. Any help would be greatly appreciated.
Thanks in advance =)
--Dan
I'm an experienced programmer, but I'm a complete newbie in the realm of VBA. I've got a problem that I can't seem to answer with my combination of books/google/help files, and I searched here and couldn't find an answer either. I'm writing a macro to parse through an RTF file making formatting changes on certain text selections. I'd like to begin at the top, find a hard-coded key word, perform some Selection.Style and Selection.Paragraphs operations, and then move on to the next instance of the keyword. I can do all of this, but I don't know the proper way to handle loop control. Currently I just have a dummy Do/While loop (more or less as proof of concept.) My pseudocode solution looks like this:
Code:
Selection.Find {bunch of find parameters}
Selection.Find.Execute
Do While NOT END OF FILE
IF (Selection contains keyword) THEN
Format Selection properly
END IF
Loop
Obviously, the macro is more complicated than that (or else I'd just use the replace all and skip the macro altogether), but that's the top-level overview. My problem is that I don't know how to use EOF in VBA. The actual EOF function seems to require a file number which requires opening a file in the macro, which just doesn't work. I'd like to either break out of the loop at the end of file, or count the number of keywords and use that as my lcv.
This should be relatively simple, but I've failed at finding a fix in the documentation anywhere. Any help would be greatly appreciated.
Thanks in advance =)
--Dan