Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Hyperlinks with variables

Hi all-

I'm trying to write some code to generate an appointment
book, with each worksheet being a different day, with a
master calendar page with clickable links that will take
the user to the clicked day's sheet. The sheets are named
with the date, ie, 10-14-03. The variable xSheet is the
name of the sheet, ie "10-14-03". I've tried using this
code:

Sub AddLink()
Sheets("Calendar").Activate
Cells(ActiveCell.Row + 1, ActiveCell.Column).Select
xAddress = xSheet & "!R1C1"
ActiveSheet.Hyperlinks.Add Anchor:=Selection,
Address:="", SubAddress:=xAddress, TextToDisplay:=xSheet
End Sub

It does generate a link, but when clicked, it comes up
with a Reference Not Valid error. Can someone help me
tweak this code so it works?

Thanks,
Marty

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Hyperlinks with variables

You never define xsheet.

This worked for me:

Sub AddLink()
xSheet = "Sheet3"
Sheets("Calendar").Activate
Cells(ActiveCell.Row + 1, ActiveCell.Column).Select
xAddress = xSheet & "!R1C1"
ActiveSheet.Hyperlinks.Add Anchor:=Selection, _
Address:="", SubAddress:=xAddress, TextToDisplay:=xSheet
End Sub

Testing from the immediate window:
? Worksheets("Calendar").hyperlinks(1).SubAddress
Sheet3!R1C1


I am using A1 addressing and it still worked, but I would recommend using
the same addressing as your sheet.

--
Regards,
Tom Ogilvy

"Marty Lindower" wrote in message
...
Hi all-

I'm trying to write some code to generate an appointment
book, with each worksheet being a different day, with a
master calendar page with clickable links that will take
the user to the clicked day's sheet. The sheets are named
with the date, ie, 10-14-03. The variable xSheet is the
name of the sheet, ie "10-14-03". I've tried using this
code:

Sub AddLink()
Sheets("Calendar").Activate
Cells(ActiveCell.Row + 1, ActiveCell.Column).Select
xAddress = xSheet & "!R1C1"
ActiveSheet.Hyperlinks.Add Anchor:=Selection,
Address:="", SubAddress:=xAddress, TextToDisplay:=xSheet
End Sub

It does generate a link, but when clicked, it comes up
with a Reference Not Valid error. Can someone help me
tweak this code so it works?

Thanks,
Marty



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Hyperlinks with variables


-----Original Message-----
You never define xsheet.


Thanks for your reply, Tom. Your code does work, which is
interesting. Earlier in the code I use this to define
xSheet:

xSheet = xMonth & "-" & xDate & "-" & "0" & (xYear - 2000)

where xMonth, xDate and xYear are variables in a For..Next
loop. If I run the code and ?xsheet from Immediate, it
comes back as 11-1-03 (starting date is 11/1), but the
link doesn't work. If I replace the above line with:

xSheet = "zzz"

the link works fine. Maybe Excel doesn't like the way I
built the sheet name?? Any other suggestions?

Thanks again!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Hyperlinks with variables

Sub AddLink()
xMonth = 11
xDate = 1
xYear = 2003
xSheet = xMonth & "-" & xDate & "-" & "0" & (xYear - 2000)
xSheet1 = "'" & xSheet & "'"

Sheets("Calendar").Activate
Cells(ActiveCell.Row + 1, ActiveCell.Column).Select
xAddress = xSheet1 & "!A1"
ActiveSheet.Hyperlinks.Add Anchor:=Selection, _
Address:="", SubAddress:=xAddress, _
TextToDisplay:=Left(xSheet1, Len(xSheet1) - 1)
End Sub

Seems to work.

--
Regards,
Tom Ogilvy

"Marty Lindower" wrote in message
...

-----Original Message-----
You never define xsheet.


Thanks for your reply, Tom. Your code does work, which is
interesting. Earlier in the code I use this to define
xSheet:

xSheet = xMonth & "-" & xDate & "-" & "0" & (xYear - 2000)

where xMonth, xDate and xYear are variables in a For..Next
loop. If I run the code and ?xsheet from Immediate, it
comes back as 11-1-03 (starting date is 11/1), but the
link doesn't work. If I replace the above line with:

xSheet = "zzz"

the link works fine. Maybe Excel doesn't like the way I
built the sheet name?? Any other suggestions?

Thanks again!



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Hyperlinks with variables

Thank you Tom - that solved it!

Marty


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
Not at all clear on use of variables and/or object variables JMay-Rke Excel Discussion (Misc queries) 11 July 4th 08 06:36 PM
Hyperlinks: Hyperlinks change on copy/paste? Rick S. Excel Worksheet Functions 0 November 13th 07 08:19 PM
Update 2000 Excel hyperlinks to 2003 hyperlinks lonv155 Excel Worksheet Functions 4 October 25th 07 05:51 AM
How toi turn-off hyperlinks [excel]? Email hyperlinks pop up ! jacob735 Excel Discussion (Misc queries) 1 June 22nd 07 12:57 AM
Excel Hyperlinks- cell content v. hyperlinks herpetafauna Excel Discussion (Misc queries) 2 May 23rd 06 04:39 AM


All times are GMT +1. The time now is 10:29 AM.

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"