Solved

Creating a HyperLink from a cell to a worksheet using C#

Posted on 2008-06-13
3
2,411 Views
Last Modified: 2013-12-17
I have written a C# application using VS2005.NET to generate an Excel spreadsheet.  My first worksheet contains an index to the other worksheets and I want to autogenerate a HyperLink using my C# application from cells in the first worksheet to the other worksheets.

I have seen many examples of linking to a web page and have done this using something like this:

worksheet.Hyperlinks.Add(hyperLinkRange, "HTTP:\\www.google.com",Type.Missing, Type.Missing, "Hyperlink Test");

The problem I have is I'm not sure how to reference a worksheet in the same Excel file.



0
Comment
Question by:jribble
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
katlin924 earned 500 total points
ID: 21861934
Hi. I'm currently doing the same thing in Excel.
Are you referring to linking from one worksheet to another?

Your code is actually correct. You just have to supply the necessary parameters for that.

Your code is:
worksheet.Hyperlinks.Add(hyperLinkRange, "HTTP:\\www.google.com",Type.Missing, Type.Missing, "Hyperlink Test");

Possible Solution:
worksheet.Hyperlinks.Add(hyperLinkRange, <this part is for web address like you mentioned "google">, <this is where you place the link for worksheets of the same workbook>, Type.Missing, "Hyperlink Test");

As you code, you can see a clue or the intellisense of C#, you'll see the description of the parameters.

Hyperlink.Add( 1, 2, 3, 4, 5)
1. Range of Cell
2. WebAddress
3. SubAddress (this is where I placed the link of the worksheets for the same workbook)
    -- format is like this: 'HyperlinkTest'!A1 (assuming that your sheet name is HyperlinkTest, if not, just replace that word according to your sheetname)
4. Screen Tip
5. Display Name

I hope it works.
0
 

Author Comment

by:jribble
ID: 21876665
katlin924,

Your possible solution was helpful.  As it turns out I was missing the apostrophes.  Here is the line of code that worked for me:

indexWorksheet.Hyperlinks.Add(smsIngredientRange, "", "'" + chartWorksheet.Name + "'!A1", Type.Missing, smsIngredientCode);

Thanks,

Joe
0
 
LVL 2

Expert Comment

by:katlin924
ID: 21880020
Glad it worked. Happy to be of help. :)
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question