I am trying to write a VBA script to convert a selection in a PowerPoint presentation into a Hyperlink that references the relevant slide. The text has at the end of each line a page number which is equal to the slide number + 15. The selection function seems to truncate before the end of the selection and does not put an end quote at the end of the string resulting in the error:
Run-time error '-2147188160 (80048240)': Hyperlink (unknown member): Invalid request. This kind of object cannot have text associated with it as a hyperlink
at the .Hyperlink.TextToDisplay line, code listed below.
Sub ConvertTextToHyperlink()
Dim objShape As Shape
Dim strText As String
Dim strSubLink As Integer
'Get the selected shape
Set objShape = ActiveWindow.Selection.ShapeRange(1)
'Get the text from the shape
strText = objShape.TextFrame.TextRange.Text
'Get the slide number
strSubLink = (Right(strText, 3) + 15)
'Add hyperlink
With objShape.ActionSettings(1) 'Assuming a mouse click triggers the hyperlink
.Action = ppActionHyperlink
.Hyperlink.TextToDisplay = strText 'Display the text
.Hyperlink.Address = Null 'Set the link address
.Hyperlink.SubAddress = strSubLink 'Set the Slide number
End With
End Sub
Additionally, the text being selected has been imported from a pdf, so that may be where the issue is, but I am unsure. The Text in question takes the format of [section title] ..................................... [page number]
I have tried to adjust the strText variable thinking there might be some disconnect between its definition and objShape's definition, but nothing seems to have changed.