Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now