Antonio Almeida
Posts: 11
Joined: 2016-04-11
|
Hi,
In word and excel we can insert a link in the document by using, ie.:
WordApp.ActiveDocument.Hyperlinks.Add
Is there a way to achieve the same in PowerPoint?
Thank you.
Kind Regards,
Antonio |
|
Andrei Smolin
Add-in Express team
Posts: 18829
Joined: 2006-05-11
|
Hello Antonio,
You are right, there's no Hyperlinks.Add() method in the PowerPoint object model.
I start PowerPoint 2003 (there's no macro recorder in subsequent PowerPoint versions) and do the following in the PowerPoint UI:
- In the new presentation created by default, I start recording a VBA macro.
- Select one of the two shapes available.
- Click Insert | Hyperlink or press {CTRL}+{K}.
- Enter 'www.google.com' (without quotes).
- Press {Enter}.
- Stop recording the macro.
Here's the recorded macro:
Sub Macro1()
'
' Macro recorded 1/9/2020 by ...
'
ActiveWindow.Selection.SlideRange.Shapes("Rectangle 2").Select
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Select
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=1, Length:=0).Select
ActiveWindow.Selection.TextRange.Text = "http://www.google.com"
With ActiveWindow.Selection.TextRange.ActionSettings(ppMouseClick).Hyperlink
.Address = "http://www.google.com/"
.SubAddress = ""
.ScreenTip = ""
.TextToDisplay = "http://www.google.com"
End With
ActiveWindow.Selection.TextRange.Characters(Start:=22, Length:=0).Select
End Sub
Hope this helps.
Andrei Smolin
Add-in Express Team Leader |
|
Antonio Almeida
Posts: 11
Joined: 2016-04-11
|
Thank you Andrei.
Your macro helped a lot and I just had to make some adjustments:
Dim startchar As Integer = PowerPointApp.ActiveWindow.Selection.TextRange.Start
PowerPointApp.ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=startchar, Length:=1).Select()
PowerPointApp.ActiveWindow.Selection.TextRange.Text = linkTitle
PowerPointApp.ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=startchar, Length:=linkTitle.Length + 1).Select()
With PowerPointApp.ActiveWindow.Selection.TextRange.ActionSettings(PowerPoint.PpMouseActivation.ppMouseClick).Hyperlink
.Address = linkUrl
.SubAddress = ""
.ScreenTip = ""
End With |
|
Andrei Smolin
Add-in Express team
Posts: 18829
Joined: 2006-05-11
|
You are welcome.
Andrei Smolin
Add-in Express Team Leader |
|