Inserting a hyperlink in the bod of an outlook appt.

Status
Not open for further replies.
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
 
See if this sample helps get you started:

http://www.outlookcode.com/codedetail.aspx?id=1914

"RHFinCT" <RHFinCT> wrote in message

news:A22F41E6-62F8-480B-AF4F-1F651A957186@microsoft.com...
> 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
 
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.
wrote:


> See if this sample helps get you started:
> http://www.outlookcode.com/codedetail.aspx?id=1914

> >

>

> "RHFinCT" <RHFinCT> wrote in message
> news:A22F41E6-62F8-480B-AF4F-1F651A957186@microsoft.com...
> > 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


>
 
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.

"RHFinCT" <RHFinCT> wrote in message

news:E2FCB233-6476-4275-9A60-1344DBE48333@microsoft.com...
> 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.
 
Thanks again Ken; I really do appreciate your assistance. The code you're

suggesting works and I completely understand why, but I can't seem to

replicate the "insertafter" behavior when inserting a hyperlink. The only

useful method for the hyperlink object seems to be the Add method.

It's seems as though I would either have to be able to set the point of

insertion to the characterposition after the last charachter in the

appointment body text. The only other idea I have is to insert a string

(which I know how to do) at the end of the body text and then always search

for that string, select it and convert it into a hyperlink (if that's

possible). Once again; thanks for your patience and assistance with this

issue.
wrote:


> 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.

> >

>

> "RHFinCT" <RHFinCT> wrote in message
> news:E2FCB233-6476-4275-9A60-1344DBE48333@microsoft.com...
> > 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.


>
 
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

"RHFinCT" <RHFinCT> wrote in message

news:AE29E3D9-FC93-47DD-9304-5AAA2A1DF2CE@microsoft.com...
> Thanks again Ken; I really do appreciate your assistance. The code you're
> suggesting works and I completely understand why, but I can't seem to
> replicate the "insertafter" behavior when inserting a hyperlink. The only
> useful method for the hyperlink object seems to be the Add method.

> It's seems as though I would either have to be able to set the point of
> insertion to the characterposition after the last charachter in the
> appointment body text. The only other idea I have is to insert a string
> (which I know how to do) at the end of the body text and then always
> search
> for that string, select it and convert it into a hyperlink (if that's
> possible). Once again; thanks for your patience and assistance with this
> issue.
 
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.
wrote:


> 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

> >

>

> "RHFinCT" <RHFinCT> wrote in message
> news:AE29E3D9-FC93-47DD-9304-5AAA2A1DF2CE@microsoft.com...
> > Thanks again Ken; I really do appreciate your assistance. The code you're
> > suggesting works and I completely understand why, but I can't seem to
> > replicate the "insertafter" behavior when inserting a hyperlink. The only
> > useful method for the hyperlink object seems to be the Add method.
> > It's seems as though I would either have to be able to set the point of
> > insertion to the characterposition after the last charachter in the
> > appointment body text. The only other idea I have is to insert a string
> > (which I know how to do) at the end of the body text and then always
> > search
> > for that string, select it and convert it into a hyperlink (if that's
> > possible). Once again; thanks for your patience and assistance with this
> > issue.


>
 
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.

"RHFinCT" <RHFinCT> wrote in message

news:71D3C88F-EB8C-4111-8DB8-C4CC9E0810B1@microsoft.com...
> 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.
 
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!
wrote:


> 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.

> >

>

> "RHFinCT" <RHFinCT> wrote in message
> news:71D3C88F-EB8C-4111-8DB8-C4CC9E0810B1@microsoft.com...
> > 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.


>
 
Appointments aren't based on Word, but using the Word object model for a

WordMail object is based on Word.

"RHFinCT" <RHFinCT> wrote in message

news:C691391F-CF6F-4E70-8228-6904B4781166@microsoft.com...
> 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!
 
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

"RHFinCT" <RHFinCT> wrote in message

news:71D3C88F-EB8C-4111-8DB8-C4CC9E0810B1@microsoft.com...
> 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.

> " - " wrote:
>
> > 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



>

>> "RHFinCT" <RHFinCT> wrote in message
> > news:AE29E3D9-FC93-47DD-9304-5AAA2A1DF2CE@microsoft.com...
> > > Thanks again Ken; I really do appreciate your assistance. The code
> > > you're
> > > suggesting works and I completely understand why, but I can't seem to
> > > replicate the "insertafter" behavior when inserting a hyperlink. The
> > > only
> > > useful method for the hyperlink object seems to be the Add method.
> >> > It's seems as though I would either have to be able to set the point of
> > > insertion to the characterposition after the last charachter in the
> > > appointment body text. The only other idea I have is to insert a string
> > > (which I know how to do) at the end of the body text and then always
> > > search
> > > for that string, select it and convert it into a hyperlink (if that's
> > > possible). Once again; thanks for your patience and assistance with
> > > this
> > > issue.

>

>>
 
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.
wrote:


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

> >

>

> "RHFinCT" <RHFinCT> wrote in message
> news:C691391F-CF6F-4E70-8228-6904B4781166@microsoft.com...
> > 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!


>
 
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.

"Sue Mosher [MVP]" wrote:


> 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
> > >

> "RHFinCT" <RHFinCT> wrote in message
> news:71D3C88F-EB8C-4111-8DB8-C4CC9E0810B1@microsoft.com...
> > 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.
> > " - " wrote:
> >
> >> 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

>
> >
> >> "RHFinCT" <RHFinCT> wrote in message
> >> news:AE29E3D9-FC93-47DD-9304-5AAA2A1DF2CE@microsoft.com...
> >> > Thanks again Ken; I really do appreciate your assistance. The code
> >> > you're
> >> > suggesting works and I completely understand why, but I can't seem to
> >> > replicate the "insertafter" behavior when inserting a hyperlink. The
> >> > only
> >> > useful method for the hyperlink object seems to be the Add method.
> >> >> > It's seems as though I would either have to be able to set the point of
> >> > insertion to the characterposition after the last charachter in the
> >> > appointment body text. The only other idea I have is to insert a string
> >> > (which I know how to do) at the end of the body text and then always
> >> > search
> >> > for that string, select it and convert it into a hyperlink (if that's
> >> > possible). Once again; thanks for your patience and assistance with
> >> > this
> >> > issue.
> >
> >>


>
 
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

"RHFinCT" <RHFinCT> wrote in message

news:B962A28C-A212-427B-B4E1-9A5B13C441D6@microsoft.com...
> 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.

> "Sue Mosher [MVP]" wrote:
>
> > 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, ""
>

>> "RHFinCT" <RHFinCT> wrote in message
> > news:71D3C88F-EB8C-4111-8DB8-C4CC9E0810B1@microsoft.com...
> > > 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.
> >> > " - " wrote:
> >> >> 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

> >
> > >
>> >> "RHFinCT" <RHFinCT> wrote in message
> > >> news:AE29E3D9-FC93-47DD-9304-5AAA2A1DF2CE@microsoft.com...
> > >> > Thanks again Ken; I really do appreciate your assistance. The code
> > >> > you're
> > >> > suggesting works and I completely understand why, but I can't seem
> > >> > to
> > >> > replicate the "insertafter" behavior when inserting a hyperlink. The
> > >> > only
> > >> > useful method for the hyperlink object seems to be the Add method.
> > >>> >> > It's seems as though I would either have to be able to set the point
> > >> > of
> > >> > insertion to the characterposition after the last charachter in the
> > >> > appointment body text. The only other idea I have is to insert a
> > >> > string
> > >> > (which I know how to do) at the end of the body text and then always
> > >> > search
> > >> > for that string, select it and convert it into a hyperlink (if
> > >> > that's
> > >> > possible). Once again; thanks for your patience and assistance with
> > >> > this
> > >> > issue.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
Witzker Pls help to change the code for inserting date in Ol contact body Outlook VBA and Custom Forms 5
D Inserting sender name and address with vba Outlook VBA and Custom Forms 1
W Inserting Additional Email Address Outlook VBA and Custom Forms 4
G Message template / custom forms and VBA Help needed - inserting info into table Outlook VBA and Custom Forms 3
D Using Libraries when inserting a file in Outlook 2013 Using Outlook 1
L Inserting a PPT/PDF into the message body Using Outlook 1
B Outlook 2007 - Slow opening folders when inserting attachments Using Outlook 2
S Inserting Dates With Quick Parts (or Macros) Using Outlook 4
L Block others from inserting appointments in your calendar Using Outlook 3
W inserting activeX/user control into form Outlook VBA and Custom Forms 1
H C# inserting word document with formatting into outlook message Outlook VBA and Custom Forms 1
K Inserting text from a macro Outlook VBA and Custom Forms 1
V Embedding hyperlink into Word document Using Outlook 2
Y Open and Save Hyperlink Files in multiple emails Outlook VBA and Custom Forms 9
L Ignore hyperlink from being flagged as false pattern Outlook VBA and Custom Forms 3
D Custom form with html hyperlink Outlook VBA and Custom Forms 7
N open the hyperlink in Outlook directly instead of browser Using Outlook 1
M VBA Rule for removing all body but hyperlink then forwarding Outlook VBA and Custom Forms 9
M How to view the URL for a hyperlink? Using Outlook 1
A Add Hyperlink to Task Outlook VBA and Custom Forms 11
Q Why can't I copy image with embedded hyperlink from email to Word Using Outlook 0
P URL Hyperlink not working correctly in Outlook 2003 Using Outlook 10
A Create Macro for hyperlink(email) in message body Outlook VBA and Custom Forms 9
Diane Poremsky Disable the Unsafe Hyperlink Warning when Opening Attachments Using Outlook 0
V Using custom field data in mail body + mailto hyperlink Outlook VBA and Custom Forms 7
C Hyperlink to an Outlook search Using Outlook 1
makinmyway Recent Files Not Updating when Using Insert Hyperlink in Outlook 2013 Using Outlook 0
E Create a URL hyperlink in an Outlook custom form? Outlook VBA and Custom Forms 2
J Macro generating email using default signature and hyperlink Outlook VBA and Custom Forms 5
Witzker HYPERLINK "mailto:test@test.com" in form body Using Outlook 21
Hudas Hyperlink Saved Outlook Email to MS Access Table Using Outlook 4
D Particular Facebook "Hyperlink" Issue In Office 2010 Outlook (32 bit) Using Outlook 5
S email body without "HYPERLINK" ( vba ) Using Outlook 6
M How to create a hyperlink to to an organizational form Using Outlook 5
J Hyperlink VBA Using Outlook 1
P Can't add a custom hyperlink to toolbar in OL 2010 Using Outlook 1
T Desable Hyperlink on email Using Outlook 3
O Hyperlink formatting lost after replacement in outlook Using Outlook 5
O Hyperlink formatting lost after replacement in outlook Using Outlook 0
G Hyperlink Using Outlook 1
T Hyperlink Issue Using Outlook 2
P Hyperlink to Access record/Form Outlook VBA and Custom Forms 2
M auto click hyperlink?! Outlook VBA and Custom Forms 1
M Auto click a hyperlink Outlook VBA and Custom Forms 2
K Add Hyperlink in Email Body by VBA Outlook VBA and Custom Forms 1

Similar threads

Back
Top