Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Automatically insert code into worksheet via macro

I'd like to be able to insert the code below into the selected
worksheet when the user runs a macro. Is it possible to run a macro
that will insert this pre-written code into a worksheet?



'*******************
'paste this code into a tab. whenever it's activated it will create an
index of each
'sheet in the workbook dynamically and then also put a return link on
each tab
'*******************

Private Sub Worksheet_Activate()
Dim wSheet As Worksheet
Dim M As Long
M = 1
With Me
.Columns(1).ClearContents
.Cells(1, 1) = "INDEX"
.Cells(1, 1).Name = "Index"
End With

For Each wSheet In Worksheets
If wSheet.Name < Me.Name Then
M = M + 1
With wSheet
.Range("H1").Name = "Start" & wSheet.index
.Hyperlinks.Add Anchor:=.Range("H1"), Address:="",
SubAddress:="Index", TextToDisplay:="Back to Index"
End With
Me.Hyperlinks.Add Anchor:=Me.Cells(M, 1), Address:="",
SubAddress:="Start" & wSheet.index, TextToDisplay:=wSheet.Name
End If
Next wSheet
End Sub






Reply
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
Code for my Command Button to automatically copy and insert a new tommy Excel Discussion (Misc queries) 0 January 28th 09 12:22 AM
Macro to insert this formula automatically on start up [email protected] Excel Programming 10 November 7th 05 10:22 PM
Automatically insert signature in worksheet John Davies Excel Programming 4 September 9th 05 12:00 PM
automatically insert town name after entering zip code accessnovice Excel Discussion (Misc queries) 2 July 12th 05 10:01 PM
Automatically Insert Text Into Macro Carl Bowman Excel Programming 7 February 12th 05 11:45 PM


All times are GMT +1. The time now is 04:19 PM.

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

About Us

"It's about Microsoft Excel"