Tricky Word Find Problem

E

Evan Stone

I've got a problem that's got me stumped (primarily because of my lack of
experience with the Word object model, in addition to a project timeline
that demands that I have this done *yesterday*...)

Anyway, I'm sure this will be fairly straightforward to a Word VBA guru, but
I was wondering how I can use Word's Find functionality to locate the start
and end of a rudimentary custom tag.

For example, imagine that we need to find the tag {*MyTag*}, but I *don't*
know what's between the initial "{*" and the end "*}" symbols (it could be
MyTag, but it also could be YourTag. I'd like to be able to locate the
beginning brace, remember it's location, find the end brace, then be able to
process whatever's between the two, doing something different for MyTag vs.
YourTag.

I'm just a little confused with how to do it in Word, so if anyone can help
me out I'd really appreciate it!

Many Thanks,

evan stone | software engineer
 
E

Evan Stone

OK, it looks like I may have found something that I can work with...

The Execute method of the Find object has a MatchWildcards argument that I
can use to find the pattern I need, so I think I'm good to go, especially
when coupled with the following article:

http://office.microsoft.com/en-us/assistance/HA010873051033.aspx

I may continue my research and see if I can get regular expressions to work,
but I think this is going to be sufficient for the time being...

thanks!

evan stone | software engineer
 
E

Evan Stone

Just as a follow up, in case someone was actually looking at this thread....

The Execute method with the MatchWildcards flag set to true works great --
the only caveat is that if you want to search for characters that are
already reserved by the wildcard search, like [, ], ?, *, etc., then you
_must_ insert a backslash character (like an escape character in C/#/++)
before each character.

So if you want to find a question mark while wildcards are enabled, your
search string in Word would be "\?" plus whatever other characters you're
looking for according to the Wildcard search rules.

Of course, if you're using C# for your automation, remember to insert *two*
backslashes in your string, so the search string in C# would look like:
"\\?"

Hope this helps anyone who comes along after me with this problem!

evan stone | software engineer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top