Fetching Hyperlinks from textbox

J

John

Hi !
I am faced with a problem.
I need to know all the hyperlinks in a PPT .
I am using the following two ways to extract them, but neither is satisfying
my requirement.
1)
For Each hl In ActivePresentation.Slides(1).Hyperlinks
With hl
MsgBox .Address
MsgBox .SubAddress
MsgBox .ScreenTip
MsgBox .TextToDisplay
MsgBox .Type
End With

This gives me all the hyperlinks but it does not give me on which object
they are applied.
Can I get them?
If yes can I get them for a particular portion of text in a textbox. with
the below method I can get the hyperlink if it is applied on the shape.

2) Set myShape = ActivePresentation.Slides(1).Shapes(1)
With myShape.ActionSettings(ppMouseClick).Hyperlink
MsgBox .Address
MsgBox .SubAddress
MsgBox .ScreenTip
MsgBox .TextToDisplay
End With
 
J

John

Thanks Shyam for the help.
but this does not completely solve my problem.
I explain how.
Just an imaginary scenario where in I have text box with the text written
"This is a link to site1 This is a link to site2" and 2 different hyperlinks
have been applied on the word 1st and 2nd word Link.
Now how do I get to know that which Hyperlink belongs to which Link?
I hope I have been able to make my problem clear.
It would be great if you could help me solve this.
 
S

Shyam Pillai

John,
Did you try running the example code?
"This is a link to site1 This is a link to site2" and 2 different
hyperlinks have been applied on the word 1st and 2nd word Link.

Set up a sample textbox as you've mentioned. Two separate links applied to
the words site1 (http://skp.mvps.org) and site2 (http://www.pptfaq.com)
Run the code, here is the output of it:
Slide number: 1
Hyperlink count: 2
1 Hyperlink: http://skp.mvps.org/
Associated TextRange: Site1, of shape: Rectangle 2
2 Hyperlink: htt://www.pptfaq.com/
Associated TextRange: Site2, of shape: Rectangle 2

Doesn't it enumerate the textrange to which each individual link is
associated?
 
J

John

Shyam Pillai said:
John,
Did you try running the example code?


Set up a sample textbox as you've mentioned. Two separate links applied to
the words site1 (http://skp.mvps.org) and site2 (http://www.pptfaq.com)
Run the code, here is the output of it:
Slide number: 1
Hyperlink count: 2
1 Hyperlink: http://skp.mvps.org/
Associated TextRange: Site1, of shape: Rectangle 2
2 Hyperlink: htt://www.pptfaq.com/
Associated TextRange: Site2, of shape: Rectangle 2

Exactly this is the precise Output that comes but I need it a bit different.
I'll try and explain with ur example
Set up a sample textbox as you've mentioned. Two separate links applied to
the words site1 (http://skp.mvps.org) and site1 (http://www.pptfaq.com)
(Note "Site1" for both the links) or in my example
This is a link(www.abc.com) to site1 This is a link(www.xyz.com) to site2
(Note the link is on the same word 'LINK' hence the problem)
The output for this will be
Slide number: 1
Hyperlink count: 2
1 Hyperlink: http://skp.mvps.org/
Associated TextRange: Site1, of shape: Rectangle 2
2 Hyperlink: htt://www.pptfaq.com/
Associated TextRange: Site1, of shape: Rectangle 2

or
for my example will be
Slide number: 1
Hyperlink count: 2
1 Hyperlink: www.abc.com
Associated TextRange: Link1, of shape: Rectangle 2
2 Hyperlink: www.xyz.com
Associated TextRange: Link1, of shape: Rectangle 2

I know you might think this is as if creating problem unnecessarily but I
faced a similar problem in the real world
so I would request you to kindly give me some solution to this.

Thanks.
 
S

Shyam Pillai

Hello John,
I haven't understood the problem. Though both links have the same text
(site1/link) they represent different textranges.
 
J

John

Shyam Pillai said:
Hello John,
I haven't understood the problem. Though both links have the same text
(site1/link) they represent different textranges.
OK, Now I think this is getting more and more confusing for you.
as you said that "Though both links have the same text
(site1/link) they represent different textranges." I say the same thing but
my problem is how to get to know the difference between the 2 textranges.
How do I get to know that which link is for which Textrange since the output
of the both the textranges is exactly the same.
1 Hyperlink: http://skp.mvps.org/
Associated TextRange: Site1, of shape: Rectangle 2 [how do I get to know the
difference between this and the next output]
2 Hyperlink: http://www.pptfaq.com/
Associated TextRange: Site1, of shape: Rectangle 2 [how do I get to know the
difference between this and the previous output]

I need to know the textrange to which the particular link refers to but to
determine this I need to know more than just the text of the textrange.
Kindly let me know if there is any way out through which I can get the exact
position or the starting character position w.r.t to the textbox.
In the above example the out put for the both the cases is the same [
Associated TextRange: Site1, of shape: Rectangle 2 ] , so how do I get to
know which output refers to what.
You can assume that I need to recreate this thing on some other presentation
and I need to store it for that purpose.

I hope this time I have been able to explain my problem and you'll be able
to help me out.
Thanks for the response and the patience.
 
H

Hans W. Hofmann

Hm, as Shyam, I am not sure to understand the whole problem too?
You get the Linktext in property .TextToDisplay? Right?
And this is in both cases the same? Right?

If you want to identify the appropriate text in shapes textrange yon
have to step througth .words list and look for
..words(i).ActionSettings(ppMouseClick).Action = ppActionHyperlink
and then go to .Hyperlink.Address or .Hyperlink.SubAddress
to find the linked address...

Hope that helps
 
S

Steve Rindsberg

Depending on what you need to do, it might be useful to loop through the
characters or words collection of the shape's TextFrame.TextRange and examine
the .ActionSettings(1).Hyperlink.Address property of each character.

That'd allow you to map out what ranges of characters have hyperlinks
 

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

Similar Threads


Top