LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Programmatically creating hyperlinks

I have one worksheet that lists a bunch of titles. Then for each title in the
first worksheet, I have another worksheet that corresponds to one of those
titles on the first worksheet. I could have up to 250 worksheets, one for
each title in the first worksheet. Can someone provide me with a way to
programmatically make the titles on the first sheet become hyperlinks that
point to its corresponding sheet in the workbook. Plus, this is a dynamically
workbook. Each week, it will have different titles and corresponding
worksheets for each, so I need to be able to save this code for use each week
when I create this workbook.

I've tried working on it myself, but am getting stuck on how to get to the
correct sheet for each title. My attempt is below if anyone needs a good
laugh :)

Any help will be greatly appreciated.

Code:
Sub LinkSheets()
    Dim myRange As range
    Dim lastCell As Object
    Dim lastLoop As Boolean
    Dim sheetNumber As Integer
    
    'find the last cell so we know when to stop.
    With ActiveSheet
        Set lastCell = .Cells(.Rows.Count, "A").End(xlUp)
    End With
    
    'Select the row in the first worksheet that I want.
    range("A:A").Select
    
    For Each cell In Selection
        If lastLoop Then
            Exit For
        Else
            If cell.Value = lastCell Then
                lastLoop = True
            End If
            
            'Make sure I am not trying to link the worksheet header to 
another worksheet.
            'All good titles will have a dash.
            If InStr(1, cell.Value, "-")  0 Then
                Cells.Find(What:=cell.Value, After:=ActiveCell, 
LookIn:=xlValues, _
                    LookAt:=xlPart, SearchOrder:=xlByColumns, 
SearchDirection:=xlNext, _
                    MatchCase:=False, SearchFormat:=False).Activate
                
                Dim workSheetCount As Integer
                Dim x As Integer
                workSheetCount = ActiveWorkbook.Worksheets.Count
                
                'Get stuck here trying to go to the next sheet and search 
for my title
                'to see if this is the corresponding sheet I need for this 
title.
                For x = 1 To workSheetCount
                    ActiveWorkbook.Sheets(x).Select
                    Cells.FindNext(After:=ActiveCell).Activate
                Next
                
                'Once I do find the correct sheet, I hope this will create 
the hyperlink I want
                ActiveSheet.Hyperlinks.Add Anchor:=cell, _
                    Address:="", SubAddress:=ActiveCell.Address, 
TextToDisplay:=cell.Value
                    
                'Then I want to create a "back" hyperlink to take the user 
back to the
                'master page (first page).
            End If
        End If
    Next cell
End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
help creating new hyperlinks programmatically J Links and Linking in Excel 1 January 14th 08 08:15 AM
Programmatically inserting hyperlinks FrigidDigit[_2_] Excel Programming 8 October 19th 05 03:50 PM
Programmatically creating a map from data in Excel David Brockus Excel Programming 0 April 8th 05 09:57 PM
Programmatically Creating Worksheet Event The Vision Thing Excel Programming 0 October 15th 04 03:52 PM
Creating Sub CommandButton1_Clk programmatically Jag Man Excel Programming 7 December 14th 03 08:49 PM


All times are GMT +1. The time now is 12:00 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"