Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Use current sheet name in Macro

Matt,

Something like this should work, though I wasn't sure where you wanted
the hyperlink to point: this should give you an idea of what to do in
any event.....

Sub Add_Hyperlinks_to_Branch_sheet2()
Dim SheetName As String
Dim BranchName As String

SheetName = ActiveSheet.Name
BranchName = Range("A1").Value

ActiveSheet.Hyperlinks.Add Anchor:=Range("A1"), Address:="",
SubAddress:= _
"'" & SheetName & "'!A10", TextToDisplay:=BranchName

End Sub

Although you don't need to use variables at all:

Sub Add_Hyperlinks_to_Branch_sheet3()
ActiveSheet.Hyperlinks.Add Anchor:=Range("A1"), Address:="",
SubAddress:= _
"'" & ActiveSheet.Name & "'!A10",
TextToDisplay:=Range("A1").Value
End Sub

HTH,
Bernie
MS Excel MVP

"Matthew Wood" wrote in message
...
Hi,

I have a worksheet that I want to creat a number of hyperlinks using

a macro. I created a macro by recording actions a sample is shown
below. The sheetname I created the macro in is called 'Branch #33-48'
and the contents of the cell that I 'goto' (R1CI) is 'Branch #33'.

What I want to do is create lots of different sheets and run the

macro against all of them. The problem is I would need to keep
editing the macro replacing the sheetname and cell contents.

Is there a way that I can declare SHEETNAME and BRANCHNAME as

variables assign the current sheetname to SHEETNAME and contents of a
cell to BRANCHNAME and then use the variables as input to
ActiveSheet.Hyperlinks.Add Anchor function.

Thanks

Matt

Sub Add_Hyperlinks_to_Branch_sheet()
'
' Add_Hyperlinks_to_Branch_sheet Macro
' Macro recorded 19/01/2004 by Matthew Wood
'
'
Application.Goto Reference:="R1C1"
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="",

SubAddress:= _
"'Branch #33-48'!A10", TextToDisplay:="Branch #33"
Range("D12").Select

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
Display current sheet name being processed in macro Ann New Users to Excel 5 April 17th 07 01:18 PM
How can I Run a query from VB macro with out affect current data in the same sheet? oafdl Excel Discussion (Misc queries) 0 May 29th 06 09:42 PM
UDF is updateing cells on another sheet with count from current sheet. John Excel Discussion (Misc queries) 3 March 20th 06 03:58 PM
Saving only current sheet Jerry Park Excel Programming 3 December 29th 03 09:18 PM
print current sheet Joe[_17_] Excel Programming 0 July 9th 03 07:43 PM


All times are GMT +1. The time now is 06:46 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"