Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-06-13
3
Medium Priority
?
2,414 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

610 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