Hyperlink - Adding text as a hyperlink

J

John Smith

Hi,

We export text from an Access application to populate Bookmarks already in
place in a Word Template.

With appWord.ActiveDocument.Bookmarks

.Item("Sentby").Range = strSentBy
.Item("Person").Range = strPerson
.Item("Customer").Range = strCustomer

End With

Now strSentBy is my email address - i.e. "(e-mail address removed)"

The code above inserts my email address OK but not formatted as a hyperlink.

Can anyone help?

Thanks in anticipation - Malcolm
 
J

Jonathan West

John Smith said:
Hi,

We export text from an Access application to populate Bookmarks already in
place in a Word Template.

With appWord.ActiveDocument.Bookmarks

.Item("Sentby").Range = strSentBy
.Item("Person").Range = strPerson
.Item("Customer").Range = strCustomer

End With

Now strSentBy is my email address - i.e. "(e-mail address removed)"

The code above inserts my email address OK but not formatted as a
hyperlink.

Can anyone help?

change the strSentBy line to this

Dim oRange as Range
Set oRange = .Item("Sentby").Range
oRange = strSentBy
appWord.ActiveDocument.Hyperlinks.Add Anchor:=oRange, _
Address:="mailto:" & strSentBy


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
J

John Smith

Hi Jonathon - that works just fine (I just had to add the appWord reference
when setting oRange for any other readers of the topic)

as in:

Dim oRange As Range
Set oRange =
appWord.ActiveDocument.Bookmarks.Item("SentBy").Range
oRange = strSentBy
appWord.ActiveDocument.Hyperlinks.Add Anchor:=oRange, _
Address:="mailto:" & strSentBy

Can you explain the significance of the "mailto:" element of
Address:="mailto:" & strSentBy as "mailto:" doesn't physically show up in
the document (and neither do I want it to!)

Grateful thanks already.

Malcolm
 
J

Jonathan West

Can you explain the significance of the "mailto:" element of
Address:="mailto:" & strSentBy as "mailto:" doesn't physically show up in
the document (and neither do I want it to!)


The mailto: reference defines the hyperlink as an email reference rather
than a web reference. With it, Word will know to start up your email
application rather than your web browser. You'll find that it is already
there in email addresses that are typed in the normal way.

As an experiment, type an email address into a document and let it
automatically convert itself to a hyperlink. Select the address, open the
VBA editor, open the Immediate window, and type the following and press
Enter

? Selection.Hyperlinks(1).Address

You'll find that mailto: has been automatically included in the address.

Similarly, if you type a web address into the document, and do the same
thing, you will find that http:// has automatically been added.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
J

John Smith

Many thanks for the information & time you spent on my questions - hugely
appreciated.

Malcolm
 

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