Solved

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

Posted on 2008-06-13
3
2,412 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

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

707 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