How do I add a hyperlink to a shape in Excel using ActiveX?

I'm looking for a way to add a hyperlink to a shape in Excel. Basically I found this tip here works great with cells in Excel: https://de.mathworks.com/matlabcentral/answers/22768-add-a-hyperlink-in-excell-through-matlab#answer_29968
From the MSDN-Documentation (search for ff822490 on msdn.microsoft.com) I found that the Hyperlinks.Add method used in the link above supports a range of cells or a shape object as anchor. I can select the respective shape (this gives me an Interface.00024430_0000_0000_C000_000000000046 in my workspace), but when I try to add a link to my selection I get this error message: Error using Interface.00024430_0000_0000_C000_000000000046/Add Invoke Error, Dispatch Exception: Wrong Parameter.
Has anyone of you used the Hyperlinks.Add method with shapes successfully? Does the method delivered with Matlab support the shape feature? Are there any workarounds?
I'm using Matlab R2016b.
Any help would be greatly appreciated :-)
Here is the script I'm using:
excel=actxserver('excel.application'); %Initialize Excel
excelWorkbook=excel.Workbooks;
excelFile=excelWorkbook.Open(sumTableTemplate); %open the Excel-file stored in 'sumTableTemplate'
excelSheet=excelFile.Sheets.Item('Summary'); %select the Excel sheet 'Summary'
% Adding a link to a cell works just perfect:
selection=excelSheetData.Range('E86'); %select the respective cell
excelSheetData.HyperLinks.Add(selection,pathLong,'','','Link to folder'); % add a link to the folder stored in 'pathLong' and write 'Link to folder' in the cell
%
% Trying to add a link to a shape in the document:
selection=excelSheet.Shapes.Range('Grafik 1'); % select the shape called 'Grafik 1'
selection.HyperLinks.Add(selection,pathLong); % trying this throws an error message: Undefined function or variable 'HyperLinks'.
excelSheet.HyperLinks.Add(selection,pathLong); %trying this throws the error message mentioned above

回答 (0 件)

質問済み:

2017 年 3 月 17 日

編集済み:

2017 年 3 月 20 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by