Inserting a hyperlink in the bod of an outlook appt.

R

RHFinCT

I'm looking for a way to insert a hyperlink into the body of an appointment
using VBA. I would like to either insert the hyperlink at the end of whatever
text exists or be able to find and select a string and then create a
hyperlink from the selection. I would then like to be able to update that
same hyperlink if the destination changes. I'm in an environment that has
users on 2003 and 2007 and although I know vba in excel pretty well, I'm a
novice with outlook vba. Thanks in advance for any assistance and especially
sample code that will help me to solve this problem
 
R

RHFinCT

Hi Ken; thanks very much for responding to my request. I have in fact worked
with this very code snippet, but it always inserts the code at the beginning
of the body text. I need to insert the code at the very end of the text. I
spent a couple of hours searching the internet for a solution on this last
night, but was not successful.
 
K

Ken Slovak - [MVP - Outlook]

The code sample uses an If test like this:

If objDoc.ProtectionType = wdAllowOnlyReading Then
msg.Body = strLink & " " & msg.Body
Else
Set objSel = objDoc.Windows(1).Selection
objSel.InsertAfter strLink & " "
End If

If you change this line:
msg.Body = strLink & " " & msg.Body
To this it should do what you want:

msg.Body = msg.Body & " " & strLink

Using the Word object model you'd get the Range of the entire text and use
the InsertAfter method of the Selection object.
 
K

Ken Slovak - [MVP - Outlook]

What Add method are you talking about?

To insert the text you want at the very end of the Word Document object you
could even use this one liner, assuming that doc is your Document object:

doc.Content.InsertAfter strLink
 
R

RHFinCT

I'm not trying to add text; I'm trying to add a hyperlink using

objDoc.Hyperlinks.Add objSel.Range, strLink, _
"", "", strLinkText, ""

The add method I am referring to is available in the hyperlinks collection.
I am able to successfuly add a hyperlink, but for reasons I won't bore you
with, it needs to follow (be at the end of) any text that already exists in
the body text window. After doing this; I then need to know how to find and
modify the hyperlink when the destination changes. Thanks very much.
 
K

Ken Slovak - [MVP - Outlook]

Since this is now getting into the Word object model completely I'd suggest
posting in a Word programming group. Most of us here use Word code sometimes
but aren't expert in it.
 
R

RHFinCT

Thanks very much Ken; I really didn't realize that calendar appointments were
based upon the word object model. I'll try there next and again, thanks for
working with me on this!
 
K

Ken Slovak - [MVP - Outlook]

Appointments aren't based on Word, but using the Word object model for a
WordMail object is based on Word.
 
S

Sue Mosher [MVP]

The first parameter of the Hyperlinks.Add method refers to the position
where you want to link to appear. As Ken suggested, the Document.Content
object returns a Range that represents the entire document. Thus, you should
be able to use that range in your Hyperlinks.Add statement:

Set myRange = objDoc.Content
objDoc.Hyperlinks.Add myRange, strLink, _
"", "", strLinkText, ""

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
Joined
Jun 18, 2005
Messages
2
Reaction score
0
Insert hyperlinks in any outlook appointment item

This works only for Mail item. How can we insert hyperlinks in any outlook appointment item ?
 
R

RHFinCT

Thanks Ken; I guess what I should've said is that I didn't realize that I
should be trying to solve a problem I'm working on with Outlook appointments
in the Word based programming group. I still haven't got this solved and I
have to believe that there is a way to do this so I'll keep searching. Again;
thanks for taking the time to help me with this.
 
R

RHFinCT

Thanks for responding Sue. I have been away for awhile which is why I have
not responded. If the myRange = objDoc.Content which represents the entire
document; how do I say "put this hyperlink at the very end (after the last
line) of myrange? I have your book; would this be covered somewhere in the
book? I have been coding VBA in Excel for many years (self taught), but I am
very new to Outlook so I apologize if I'm struggling to get this to make
sense.
 
S

Sue Mosher [MVP]

Sorry, but the example I gave earlier wasn't a good one. Instead of using
the Range returned by the entire document content, you should move the
selection to the end of the document (the kind of thing that the Word macro
recorder is very good at revealing):

Set objDoc = objInsp.WordEditor
Set objSel = objDoc.Windows(1).Selection
objSel.Move wdStory, 1
objDoc.Hyperlinks.Add objSel.Range, strLink, _
"", "", strLinkText, ""

These techniques are covered in Chapter 17 of my Outlook 2007 book, which is
also available online at
http://msdn.microsoft.com/en-us/library/dd492012.aspx
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 

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