Bookmark Brief Introduction
In different environments, bookmarks has different definitions. When reading a book, a bookmark is a piece of paper that is inserted in a book to record which page we have read to. When browsing websites, we can add some interesting and useful webpages as bookmarks to conveniently and quickly return to another time. In MS Office, a bookmark is a function to help users go to a specified location quickly and easily. This article focuses on how to realize a bookmark function in MS Excel.
Preparation
In my example, I prepare two workbooks.
Workbook 1
This workbook is a sales report. It includes many worksheets. From worksheet 2 to 6, it shows vendor sales reports, while the latter worksheets show a commission report.
Vendor sales information includes two parts, Parts and Orders. Orders information is related to Parts. For example, the fourth worksheet shows orders information about PartNo K01-07. Commission report includes information in year 2010 and 2011.
Workbook 2
This workbook just has only one worksheet which saves information about staff.
Bookmark List
What I will do is to create a bookmark in the first worksheet of Workbook 1. There are five main bookmark titles, vendor sales report, 2010 commission report, 2011 commission report, Staff information and e-iceblue (a website). Also, I set some other vice bookmark titles under the main bookmarks.
The effect will be as in the following image:


Step
1. Write sub-methods for calling them in the main method.
DrawInternalHyperlink
If we want to move to other worksheets once clicking relevant bookmark title, we need to draw hyperlink for titles. Select bookmark range and add hyperlink in worksheet. Then, set type. Because the bookmark points to internal worksheet, so set type as workbook. Finally, set hyperlink text and jump to where after clicking it.
- static private void DrawInternalHyperlink(Worksheet sheetSource, Worksheet sheetDest, int rowIndex, string text)
- {
- CellRange range = sheetSource.Range[rowIndex, 2];
- HyperLink hyperlink = sheetSource.HyperLinks.Add(range);
- hyperlink.Type = HyperLinkType.Workbook;
- hyperlink.Address = text;
- hyperlink.SubAddress = sheetDest.Range["A1"].RangeGlobalAddress;
- }
DrawExternalHyperlink
The fourth bookmark title points to Workbook 2, so set external hyperlink. Also, select range, add hyperlink and set hyperlink type as file. After setting text, add a file path.
- static private void DrawExternalHyperlink(Worksheet sheetSource, int rowIndex, string text)
- {
- CellRange range = sheetSource.Range[rowIndex, 2];
- HyperLink hyperlink = sheetSource.HyperLinks.Add(range);
- hyperlink.Type = HyperLinkType.File;
- hyperlink.TextToDisplay = text;
- hyperlink.Address = @"C:\Users\lenovo\Desktop\bookmark\bookmark\StaffInfo.xlsx";
- }
DrawUrlHyperlink
The fifth bookmark title moves us to a website, so draw a URL hyperlink. Select range, add a hyperlink and set hyperlink type as URL. Add text and website address.
- static private void DrawUrlHyperlink(Worksheet sheetSource, int rowIndex, string url)
- {
- CellRange range = sheetSource.Range[rowIndex, 2];
- HyperLink hyperlink = sheetSource.HyperLinks.Add(range);
- hyperlink.Type = HyperLinkType.Url;
- hyperlink.TextToDisplay = "5 E-iceblue";
- hyperlink.Address = url;
- }
SetFormat
This method is used to set bookmark list format, including font style, background color and indentation.
Stelia JacksonPosted Jan 19, 2012, 11:11 PM
vry nicely presented
Stelia JacksonPosted Jan 19, 2012, 11:10 PM
vry nicely presented
Sanjoli GuptaPosted Jan 19, 2012, 3:39 AM
hmm very nicely presented...
Sonakshi SinghPosted Jan 19, 2012, 3:19 AM
Useful article for people who works on Excel.
Amit MaheshwariPosted Jan 18, 2012, 5:38 PM
It's a auspicious effort to accomplish such type of task and it's very helpful to us so please keep it up......
Abhi KumarPosted Jan 16, 2012, 11:17 PM
Very useful article.
Adora KrausePosted Jan 16, 2012, 11:02 PM
You have presented your article very nicely.
Jimmy UnderwoodPosted Jan 16, 2012, 5:29 PM
Thanks
Arjun PanwareditedPosted Jan 16, 2012, 5:12 PMEdited Jan 17, 2012, 2:29 PM
appreciation for this article