A family of Microsoft presentation graphics products that offer tools for creating presentations and adding graphic effects like multimedia objects and special effects with text.
It's pretty unclear what you need the hyperlink to do!
Why are you setting the Width and Height of the added picture to 100? It makes no sense:
A You already know the correct width and Height so you could just plug them in
B I would never do this anyway unless you are certain you know the exact sizes.
It's a common misconception that you must specify a height and width when adding pictures. You don't they are optional. If you just leave them out the picture will be inserted at its real size AND lockAspectratio will be set to True so that you only need adjust the height OR width to get the size needed with no distortion.
Sub ExistingSlides()
Dim strTemp As String
Dim strPath As String
Dim strFileSpec As String
Dim oSld As Slide
Dim oLayout As CustomLayout
Dim oPic As Shape
Dim oTxt As Shape
' Edit these to suit:
strPath = "d:\My Pictures"
strFileSpec = "*.jpg"
strTemp = Dir(strPath & strFileSpec)
Do While strTemp <> ""
Set oLayout = ActivePresentation.Designs(1).SlideMaster.CustomLayouts(1)
Set oSld = ActivePresentation.Slides.AddSlide(ActiveWindow.View.Slide.SlideIndex, oLayout)
Set oPic = oSld.Shapes.AddPicture(FileName:=strPath & strTemp, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=0, _
Top:=0)
With oPic
' Set position:
.Left = 1.66 * 72
.Top = 0.85 * 72
' Set size:
.Height = 8.89 * 72 ' is this correct - it's very large!
End With
' Get the next file that meets the spec and go round again
strTemp = Dir
Loop
End Sub
To add an internal hyperlink you need to add an action setting to the textrange for the link and give it an action of ppActionHyperlink and specify a subAddress to the correct slide.
This example would create a link to slide 5. NOTE even if you later move the slide to a new position the link will still work.
Sub createLink()
Dim otxr As TextRange
Dim osld As Slide
Set osld = ActivePresentation.Slides(5)
'assumes there is a slide 1 with the Title & Text layout!
Set otxr = ActivePresentation.Slides(1).Shapes(2).TextFrame.TextRange.Paragraphs(1)
otxr.Text = "Link to slide 5"
With otxr.ActionSettings(ppMouseClick)
.Action = ppActionHyperlink
.Hyperlink.SubAddress = getSubAddress(osld) ' osld is slide 5
End With
End Sub
Function getSubAddress(osld As Slide) As String
Dim strID As String
Dim strIndex As String
Dim strTitle As String
strID = osld.SlideID
strIndex = osld.SlideIndex
If osld.Shapes.HasTitle Then
If osld.Shapes.Title.TextFrame.HasText Then
strTitle = osld.Shapes.Title.TextFrame.TextRange
Else
strTitle = osld.Name
End If
End If
getSubAddress = strID & "," & strIndex & "," & strTitle
End Function