Thanks Dave, I'll look that over. Since I made my original post I've
been looking over "Range" stuff. I wonder if that's what I need to use.
in your code, i'm not sure what "wdStory" is. i looked it up in VBA
help but that wasn't much [help]
It looks like the first part of the code (up to the first "end with")
is finding my magic point in the document. Let's call it "styleX"
instead of "body text". Here's some more info about that: there may be
multiple occurences of "styleX" but I am only concerned w/ finding the
FIRST occurence and performing my style replacement between that point
and the end of the document.
I"m not sure I understand how the "With .Find" thing works. Again,
"with" doesn't show up in my VB help file. Sorry, I'm kind of dense
with VB.
Hi Lighthouse,
You can use the Range object, but the routine I wrote (using the Selection
object) will work just fine. wdStory is a constant. Basically, anything in
Word VBA that starts with "wd" is a constant.If you want to know what a
constant does, then look in the help not for the name of the constant, but
the name of the method or property associated with the constant. In this
case, you would look for "HomeKey". In short
With Selection
.HomeKey Unit:=wdStory
sends the cursor to the beginning of the document. If you're only interested
in finding the first occurrence of "styleX", then send the cursor to the
beginning of the document (shown above) and then search for the style from
there (shown below). You can find "With Statement" in the VBA help file.
Take the following example:
With Selection
With .Find
.ClearFormatting
.Text = ""
.Style = "body text"
.Replacement.Text = ""
.Execute
End With
End With
Pretty easy to read, isn't it? Well, you can accomplish the same thing with
Selection.Find.ClearFormatting
Selection.Find.Text = ""
Selection.Find.Style = "body text"
Selection.Find.Replacement.Text = ""
Selection.Find.Execute
As I hope you can see, it's a little more difficult to read. BTW, it also
takes a little longer to execute. The With statement, then, does at least
two things, it makes your code a little more readable (and, therefore,
easier to maintain), and it makes your routine (especially longer ones) more
efficient in terms of execution time because "fewer dots" in a line of code
execute faster.
HTH,
Dave
> Thanks Dave, I'll look that over. Since I made my original post I've
> been looking over "Range" stuff. I wonder if that's what I need to use.
[quoted text clipped - 11 lines]
> "with" doesn't show up in my VB help file. Sorry, I'm kind of dense
> with VB.
Lighthouse - 15 Feb 2005 13:02 GMT
Thanks again, Dave. That's just what I was looking for: a little help
mixed w/ a little explanation. The help is a bit maddening to a
newcomer. Who'da thunk you get nothing by searching on "with" but find
it by searching on "with statement"? Thanks also for that info about
"wd". I've seen that, but wasn't aware that it meant a constant.