MATLAB Answers

Add Hyperlinks to Powerpoint from Matlab using ActiveX

28 views (last 30 days)
Chris
Chris on 3 Jul 2014
Answered: Laura Nichifor on 29 Aug 2018
Can someone explain how I can use matlab and activeX to add hyperlinks to powerpoint files?
This question explains how to create a powerpoint file using matlab:
This question shows how to use ActiveX to insert hyperlinks into Excel:
Add Hyperlink in Excel from Matlab (See the second answer by Kaustubha)
I tried to merge the two answers. I see that "Slide" objects have the ".Hyperlinks" attribute but there is no ".Add" method for Hyperlinks.
Here is the code I have so far:
ppt = actxserver('PowerPoint.Application'); % create a powerpoint object
template = 'link\to\template.pptx'; % path to template
op = invoke(ppt.Presentations,'Open',template,[],[],false); % open the template file
slide = invoke(op.Slides,'Item',1); % create handle for 1st slide
slide.Hyperlinks .... ? % not sure
Please share another example. I would like the links to appear in a table.
sH = op.PageSetup.SlideHeight; % slide height
sW = op.PageSetup.SlideWidth; % silde width
table = invoke(slide.Shapes, 'AddTable', 1, 3, 0.05*sW, sH*.2, 0.9*sW, sH*.60);
table.Table.Cell(1,1).Shape.TextFrame.TextRange.Text = 'www.mathworks.com';
table.Table.Cell(1,1).Shape.TextFrame.TextRange. ... add hyperlink to text
Thanks!

  0 Comments

Sign in to comment.

Answers (2)

Brandon
Brandon on 25 Oct 2016
I know this is an old question, but this might help someone in the future.
In Visual Basic you use the ActionSettings member of the TextRange. However the ActionSettings variable doesn't make it through to MATLAB cleanly. It has a count, but doesn't have anything else needed to set the Hyperlinks. I worked around this shortfall the following way:
1. I Added all the text that was to become links using normal MATLAB calls. I used different lines for each link. sprintf is important because it converts '\n' into a real return character.
txt = sprintf("Link 1\nLink 2");
linkFromSlide.Shapes.Placeholders.Item(2).TextFrame.TextRange.Text = txt;
2. I Wrote a Visual Basic Script (makeLink.vbs that takes command-line parameters to set the link
Set args = WScript.Arguments
Set ppt = CreateObject( "PowerPoint.Application" )
Set slide = ppt.ActivePresentation.Slides(CInt(args(0)))
Set line = slide.Shapes.Placeholders.Item(2).TextFrame.TextRange.Lines(args(1))
'WScript.Echo line.Text
With line.ActionSettings(1)
.Action = ppActionHyperlink
.Hyperlink.SubAddress = args(2)
End With
3. Made a system call from my MATLAB script
system(sprintf('cscript makeLink.vbs %d %d %d',linkFromSlide.SlideNumber,lineNumber,linkToSlide.SlideNumber));

  0 Comments

Sign in to comment.


Laura Nichifor
Laura Nichifor on 29 Aug 2018
if true
action = textBox.TextFrame.TextRange.ActionSettings(1);
item = action.Item(1);
item.Hyperlink.Address = 'C:\picture1.jpg';
end

  0 Comments

Sign in to comment.

Sign in to answer this question.