Add Hyperlink to Powerpoint vb.net automation

A

Anish Dantale

Hi,
I am trying to add a hyperlink to a table in a PowerPoint slide using vb.net .

Was trying the code

Dim tr As TextRange
tr = ppslide.Shapes.Item(10).Table.Cell(2, 2).Shape.TextFrame.TextRange

tr = ppapplication.ActiveWindow.Selection.TextRange.InsertAfter("Hyperlink")

tr.ActionSettings(PpMouseActivation.ppMouseClick).Action = PpActionType.ppActionHyperlink

tr.ActionSettings(PpMouseActivation.ppMouseClick).Hyperlink.Address = "c:\test.doc"



from reference http://www.vbforums.com/showthread.php? t=442549
Its not working
giving an exception "Selection (unknown member) : Invalid request. Nothing appropriate is currently selected."


What is the correct way of doing it
 
S

Steve Rindsberg

Hi,
I am trying to add a hyperlink to a table in a PowerPoint slide using vb.net .

Was trying the code

Dim tr As TextRange
tr = ppslide.Shapes.Item(10).Table.Cell(2, 2).Shape.TextFrame.TextRange

tr = ppapplication.ActiveWindow.Selection.TextRange.InsertAfter("Hyperlink")

tr.ActionSettings(PpMouseActivation.ppMouseClick).Action = PpActionType.ppActionHyperlink

tr.ActionSettings(PpMouseActivation.ppMouseClick).Hyperlink.Address = "c:\test.doc"


from reference http://www.vbforums.com/showthread.php? t=442549
Its not working
giving an exception "Selection (unknown member) : Invalid request. Nothing appropriate is currently selected."

What is the correct way of doing it

First, never select anything if you don't absolutely need to.
Get a reference to it and use that instead.
Here's an example that uses the current selected shape.
In your case, you'd change the Set oSh= line to:

Set oSh=ppslide.Shapes.Item(10)

Sub AddHyperlinkToTable()
Dim oSh As Shape
Set oSh = ActiveWindow.Selection.ShapeRange(1)
With oSh.Table.Cell(1, 2).Shape.TextFrame.TextRange
With .ActionSettings(ppMouseClick).Hyperlink
.Address = "http://www.google.com"
.TextToDisplay = "Hey, watch me google!"
End With
End With
End Sub

You'll have to translate the VBA into .NETness and understand that this works in PPT 2003 but may fail in 2007/2010
because MS never finished hooking up the OM for tables. Some code works, some doesn't.
 

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