Hi All,
I have got some useful codes for my project to automatically generating worksheets of each individual employee in the active workbook. Please see below codes for the same:
Private Sub CommandButton1_Click()
' VBA Routine to Add and Name Worksheets
Call CreateWorksheets(Sheets("Monthly Productivity Data").Range("A2:A11"))
End Sub
Option Explicit
' In a Module
Sub CreateWorksheets(Names_Of_Sheets As Range)
Dim No_Of_Sheets_to_be_Added As Integer
Dim Sheet_Name As String
Dim i As Integer
No_Of_Sheets_to_be_Added = Names_Of_Sheets.Rows.Count
For i = 1 To No_Of_Sheets_to_be_Added
Sheet_Name = Names_Of_Sheets.Cells(i, 1).Value
' Only add sheet if it doesn't exist already and the name is longer than zero characters
If (Sheet_Exists(Sheet_Name) = False) And (Sheet_Name <> "") Then
Worksheets.Add().Name = Sheet_Name
End If
Next i
Call CountMySheets ' Count the sheets in a Workbook
End Sub
' =======================================================
Function Sheet_Exists(WorkSheet_Name As String) As Boolean
Dim Work_sheet As Worksheet
Sheet_Exists = False
For Each Work_sheet In ThisWorkbook.Worksheets
If Work_sheet.Name = WorkSheet_Name Then
Sheet_Exists = True
End If
Next
End Function
' =======================================================
Public Sub CountMySheets()
' Count the sheets in a Workbook
MsgBox "Total Number of Worksheets in this Workbook = " & Application.Sheets.Count
End Sub
Could you please tell me how to automatically add hyperlinks from each employee's ID to his unique individual worksheet, so whenever we run the above codes for automatically generating the worksheets, then all of those worksheets have a hyperlink form the main worksheet - "Monthly Productivity Data".
For example: If a new sheet is generated with a name as Tom Cruise then a hyperlink should appear on his ID on the main worksheet Monthly Productivity Data. so we can visit his unique worksheet on a simple click.
Workbook: MS Excel 2003
Thanks in advance!
Plz find the attached workbook for more details.
Bookmarks