Which part of shape selected

B

Burnsie

Hi,

Environment (XP, PPT12) -- Programmatically create/edit hyperlink

I need to find out when a shape (textbox, placeholder, etc) is selected if
the textframe is selected (if the shape has a textframe) or the container.
The reason is that I want to set a hyperlink and therefore I need to know
which portion of the shape is actually selected. Also, how do I figure out
which shapes don't have a textframe.

For instance, if the user selects the shape (i.e., circle) but not the
textframe within the shape, then there is not a .TextToDisplay property.
However, if the user selects the textframe, even though there may be no text,
then I will need to handle .TextToDisplay.

In the case where the textframe is selected but no text is selected or no
text exists, I am unable to set the .TextToDisplay. I am told that this
object type doesn't have this property (basically "unknown") even though it
does. As long as some text is selected my code works fine.

Thanks for any help in pointing me in the right direction.

Burnsie
 
D

David M. Marcovitz

If you have a pointer to a shape, such as oShp, then:

oShp.HasTextFrame

will return true or false depending on whether the shape has a text
frame.

--David
 
B

Burnsie

David,

Thanks. I have no problem with this part. The problem I have is knowing if
they have only clicked the shape and not the textframe. For instance, even
though a shape may have a textframe, if the user only clicked the shape
(container) then my hyperlink would not have a .TextToDisplay property (i.e.,
MyShape.ShapeRange.ActionSettings... (doesn't have a .TextToDisplay) versus
MyShape.ShapeRange.TextFrame.TextRange.ActionSettings....(has a
..TextToDisplay).

I guess what I am trying to do is mimic the Office Hyperlink function.

Thanks for taking the time to reply to my earlier post.

Burnsie
 
D

David M. Marcovitz

Are you sure? I'm not sure I'm following you, but I get no errors when
accessing the .TextToDisplay property even for a shape that has no text
as long as it has a TextFrame.
--David
 
B

Burnsie

David,

Thanks for the reply. I got sidetracked with another issue and I am finally
getting back to solving this puzzle.

My fault on not making clear the problem. So, let me try to explain again.
I have a rectangle with text inside; let's call it Test1. If I put the
cursor between the e and s (nothing is actually selected) and try to set the
hyperlink's TextToDisplay property = "Test1" I get the following error:

Hyperlink (unknown member) : Invalid request. This kind of object cannot
have a hyperlink associated with it.

I have confirmed that the hyperlink object is the type of msoHyperlinkRange
and that the hyperlink.parent.parent = "TextRange". So, I do know that the
TextToDisplay is a valid property for this hyperlink.

I don't have this problem when the selected shape is a placeholder. Is
there another way to set the TextToDisplay property?

Thanks,

Burnsie
 
B

Burnsie

Steve,

This helps. Another problem that has cropped up that I am hoping you can
help with. It has to do with setting the TextToDisplay property (See the
reply I sent to David Marcovitz). It basically boils down to this: My
hyperlink object does have a textrange, so that should allow setting the
TextToDisplay property. And it does if something is selected or there is
nothing within the textrange. However, if the cursor is in the middle of the
word with nothing selected or between words, then it gives the following
error:

Hyperlink (unknown member) : Invalid request. This kind of object cannot
have a hyperlink associated with it.

However, this doesn't happen if the shape is a placeholder. Since I am
running my code in VSTO could something have changed with the PowerPoint
object model that makes this a read-only property for some shapes?

Thanks for your help.

Burnsie
 
B

Burnsie

Steve,

Thanks so much for staying with this thread.

My code is a variation of the PP11 Help for the TextToDisplay property.
However, even the snippet from Help blows up.

Here is the snippet from the Help file: In my case shape 2 is a rectangle
with text.

When you try to set the TextToDisplay it blows up. If the shape happens to
be a placeholder then all is fine.

With Application.ActivePresentation.Slides(1).Shapes(2).TextFrame.TextRange
With .ActionSettings(ppMouseClick)
.Action = ppActionHyperlink
.Hyperlink.TextToDisplay = "Microsoft Home Page"
.Hyperlink.Address = "http://www.microsoft.com/"
End With
End With

According to MS:

This property will cause a run-time error if used with a hyperlink that is
not associated with a text range. You can use code similar to the following
to test whether or not a given hyperlink, represented here by myHyperlink, is
associated with a text range.

If TypeName(myHyperlink.Parent.Parent) = "TextRange" Then
strTRtest = "True"
End If

As you can see in the snippet, the hyperlink object does have a textrange.

At first, I thought it was a bug with VSTO and VS2005 which is the
environment I am using. But I have tried with PP11 by itself and get the
same error. Maybe this is a bug.

Thanks again,

Burnsie
 
B

Burnsie

Steve,

First of all my apologies for not replying sooner. Your snippet took care
of my problem for the majority of cases that may happen while running our
program. So, thank you very much.

The only problem I can't solve is when I want to put a hyperlink at the end
of a line of text. I have code that will handle between words, words,
characters, sentences, etc. But I haven't figured out how to select
something when there are no characters, etc., after where the cursor is
positioned.
Anyway, I owe you for all the help you have already provided.

Our group (WEdge -- Warfighters Edge) will be at TechEd. We will be demoing
with Tim Huckaby on Tuesday at 1:15 and then again during his TLC on Thursday
at 8:30. If you happen to be at TechEd maybe I can buy you a round.

Thanks for all the help.

Burnsie
 
B

Burnsie

Steve,

OK on that.

I just returned from TechEd and can say it was well worth the trip. I was
able to make a few contacts with folks very knowledgeable in PPT.

With our project going where no one else has gone before, we had some
interesting conversations about the best way to accomplish our objectives.

Anway, thanks so much for all the help you have provided.

Burnsie
 

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