Solved

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

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

910 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

23 Experts available now in Live!

Get 1:1 Help Now