0

I am trying to add a hyperlink to a shape, but it's getting error while executing.

Exception from HRESULT: 0x800A03EC

I have created a Shape , then I have assigned an address for the hyperlink but without success. Please is that functioning in C#. The code is working without the link. Please see below code :

InteropExcel.Range r = (InteropExcel.Range)iWS.Cells[rownum, currCol];
InteropExcel.Shape sh = (InteropExcel.Shape)iWS.Shapes.AddShape(MsoAutoShapeType.msoShape4pointStar, Convert.ToSingle(r.Left), Convert.ToSingle(r.Top), 20, 20);

sh.Hyperlink.Address = "c:\\test.txt";
Manfred Radlwimmer
  • 12,469
  • 13
  • 47
  • 56
Firas S
  • 9
  • 5
  • *"but it's getting error while executing"* You might want to include the error message in your question. – Manfred Radlwimmer Feb 13 '17 at 07:43
  • From [this reference](https://support.office.com/en-us/article/HYPERLINK-function-333C7CE6-C5AE-4164-9C47-7DE9B76F577F) (maybe related): *"the HYPERLINK function is valid for web addresses (URLs) only. Link_location can be a text string enclosed in quotation marks or a reference to a cell that contains the link as a text string. If the jump specified in link_location does not exist or cannot be navigated, an error appears when you click the cell."* – Manfred Radlwimmer Feb 13 '17 at 07:45
  • ManFred I am getting that error, Error: Exception from HRESULT: 0x800A03EC. I even tried using Web addresses but the same result. I am wondering if I can do that programmatic on C#. – Firas S Feb 13 '17 at 07:50
  • Check [this question](https://stackoverflow.com/questions/12714626/exception-from-hresult-0x800a03ec-error). A lot of possible causes for that error. – Manfred Radlwimmer Feb 13 '17 at 07:54
  • Yes that is a general error, but is it possible to add a hyperlink to a shape, I googled that without any reference. – Firas S Feb 13 '17 at 07:56

1 Answers1

0

The below code show how to add links to excel shapes :

InteropExcel.Range rshx = (InteropExcel.Range)iWS.Cells[rownum, currCol];

InteropExcel.Shape shxr = (InteropExcel.Shape)iWS.Shapes
    .AddShape(MsoAutoShapeType.msoShapeDiamond, 
        Convert.ToSingle(rshx.Left), Convert.ToSingle(rshx.Top), 20, 20);

Release(rshx);

shxr.ShapeStyle = MsoShapeStyleIndex.msoShapeStylePreset31;

iWS.Hyperlinks.Add(shxr, linkurl);
Release(shxr); 
Edu
  • 1,869
  • 5
  • 27
  • 32
Firas S
  • 9
  • 5