Converting web + email addresses to hyperlinks

J

Jay

I want to convert all of the web and email addresses in an open and
active Word document to hyperlinks (ie the character style). Some may
already be hyperlink style, but some are not, and it's the ones that
are not that I want to convert. I've tried using autoformat, but this
makes other unwanted changes to my document, so I don't want to use
this method. Assuming there isn't a direct way to do this in Word, how
would I use VBA to perform this task?
 
W

Word Heretic

G'day "Jay" <[email protected]>,

Check with the w3c on valid email chartacters, but basically you can
use find and replace with wildcards here.

[A-Za-z-_!]@[@][A-Za-z-_.]@

if needed you could also bring in start of word < and end of word >
around the whole thing.





Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


Jay reckoned:
 
J

Jay

Thanks for your reply.

I couldn't get the wildcard @ to work, so I had to used {1,} instead
(@ is supposed to be the same, but for some reason isn't). Also, I
used an \ as an escape for @, - and ! since these have special
meanings in a wildcard seach. So my search string was:

<[a-zA-Z1-9\-_.\!]{1,}\@[a-zA-Z1-9\-_.\!]{1,}>

This finds an email, but on the second find, it finds the same email
address except for the first character, for intance, with
(e-mail address removed), it finds this, then finds
(e-mail address removed), which is not what I want. I tried
surrounding the entire search string with <> as you suggested, but -
and . characters in the email act as word delimiters, so it finds the
above email, but then finds (e-mail address removed), then
(e-mail address removed).

Any ideas?
 
W

Word Heretic

G'day "Jay" <[email protected]>,

Yar - Word gets in the road sometimes :). In that case you need to
wrap the find in a loop and collapse the range to its end before
finding again.

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


Jay reckoned:
Thanks for your reply.

I couldn't get the wildcard @ to work, so I had to used {1,} instead
(@ is supposed to be the same, but for some reason isn't). Also, I
used an \ as an escape for @, - and ! since these have special
meanings in a wildcard seach. So my search string was:

<[a-zA-Z1-9\-_.\!]{1,}\@[a-zA-Z1-9\-_.\!]{1,}>

This finds an email, but on the second find, it finds the same email
address except for the first character, for intance, with
(e-mail address removed), it finds this, then finds
(e-mail address removed), which is not what I want. I tried
surrounding the entire search string with <> as you suggested, but -
and . characters in the email act as word delimiters, so it finds the
above email, but then finds (e-mail address removed), then
(e-mail address removed).

Any ideas?

Word Heretic said:
G'day "Jay" <[email protected]>,

Check with the w3c on valid email chartacters, but basically you can
use find and replace with wildcards here.

[A-Za-z-_!]@[@][A-Za-z-_.]@

if needed you could also bring in start of word < and end of word >
around the whole thing.
 

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