PC Review


Reply
Thread Tools Rate Thread

Creating HyperLinks in VB

 
 
=?Utf-8?B?TWF4?=
Guest
Posts: n/a
 
      14th Nov 2006
Hi!

I'm using the following code to try and create automatic HyperLinks in my
workbook:

Sheet2.Cells(i + 5, 2).Value = strENGINE
Sheet2.Cells(i + 5, 2).Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
"'" & strENGINE & "'!A1", TextToDisplay:=strENGINE
With Selection.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 14
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleSingle
.ColorIndex = 5
End With

where strENGINE is the name of a worksheet in the same workbook. However,
when I click on the created link, I get a "Reference is not valid." error.
What can I do to correct this?

Note, strENGINE may contain a hypen in it - does this cause issues as well?
--
Thanks!
Max
 
Reply With Quote
 
 
 
 
Dennis
Guest
Posts: n/a
 
      14th Nov 2006
Max,

Adapt the following for your use. Be careful with the _ at the
end of the lines


Activesheet.Hyperlinks.Add Anchor:= YourLinkCell.address, _
Address:="", SubAddress:= "'" + MyPreviousWorksheet.Name + "'!" _
+ Replace(YourLinkCell.Cells.Address, "$", ""), TextToDisplay:="'" _
+ YourLinkCell.Cells.Formula

Notice how the sheetname is concatenated. Also, how the Absolute sign
"$" is removed from the address. I chose the to show the Formula as
the blue link text display. Of course you could use
YourLinkCell.Cells.Value

HTH EagleOne


Max wrote:
> Hi!
>
> I'm using the following code to try and create automatic HyperLinks in my
> workbook:
>
> Sheet2.Cells(i + 5, 2).Value = strENGINE
> Sheet2.Cells(i + 5, 2).Select
> ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
> "'" & strENGINE & "'!A1", TextToDisplay:=strENGINE
> With Selection.Font
> .Name = "Arial"
> .FontStyle = "Regular"
> .Size = 14
> .Strikethrough = False
> .Superscript = False
> .Subscript = False
> .OutlineFont = False
> .Shadow = False
> .Underline = xlUnderlineStyleSingle
> .ColorIndex = 5
> End With
>
> where strENGINE is the name of a worksheet in the same workbook. However,
> when I click on the created link, I get a "Reference is not valid." error.
> What can I do to correct this?
>
> Note, strENGINE may contain a hypen in it - does this cause issues as well?
> --
> Thanks!
> Max


 
Reply With Quote
 
acampbell012@yahoo.com
Guest
Posts: n/a
 
      14th Nov 2006
Added a few lines and insterted a few "" to make it work for me. I
only get the error when the sheet "strENGINE" does not exist.

Sub mytest5()
Dim i
i = 4
Sheets(2).Cells(i + 5, 2).Value = "strENGINE"
Sheets(2).Cells(i + 5, 2).Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="",
SubAddress:= _
"'" & "strENGINE" & "'!A1", TextToDisplay:="strENGINE"
With Selection.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 14
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleSingle
.ColorIndex = 5
End With
End Sub


Max wrote:
> Hi!
>
> I'm using the following code to try and create automatic HyperLinks in my
> workbook:
>
> Sheet2.Cells(i + 5, 2).Value = strENGINE
> Sheet2.Cells(i + 5, 2).Select
> ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
> "'" & strENGINE & "'!A1", TextToDisplay:=strENGINE
> With Selection.Font
> .Name = "Arial"
> .FontStyle = "Regular"
> .Size = 14
> .Strikethrough = False
> .Superscript = False
> .Subscript = False
> .OutlineFont = False
> .Shadow = False
> .Underline = xlUnderlineStyleSingle
> .ColorIndex = 5
> End With
>
> where strENGINE is the name of a worksheet in the same workbook. However,
> when I click on the created link, I get a "Reference is not valid." error.
> What can I do to correct this?
>
> Note, strENGINE may contain a hypen in it - does this cause issues as well?
> --
> Thanks!
> Max


 
Reply With Quote
 
Dennis
Guest
Posts: n/a
 
      14th Nov 2006
You appear to be attempting to use strENGINE as a variable.
>From what I can see, you have set only Sheets(2).Cells(i + 5, 2).Value

to "strENGINE."

Consider changing "'" & "strENGINE" & "'!A1" to
"'" + Sheets(2).Cells(i + 5, 2).Value "'!"

And TextToDisplay:="strENGINE" to
Sheets(2).Cells(i + 5, 2).Value

EagleOne

(E-Mail Removed) wrote:
> Added a few lines and insterted a few "" to make it work for me. I
> only get the error when the sheet "strENGINE" does not exist.
>
> Sub mytest5()
> Dim i
> i = 4
> Sheets(2).Cells(i + 5, 2).Value = "strENGINE"
> Sheets(2).Cells(i + 5, 2).Select
> ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="",
> SubAddress:= _
> "'" & "strENGINE" & "'!A1", TextToDisplay:="strENGINE"
> With Selection.Font
> .Name = "Arial"
> .FontStyle = "Regular"
> .Size = 14
> .Strikethrough = False
> .Superscript = False
> .Subscript = False
> .OutlineFont = False
> .Shadow = False
> .Underline = xlUnderlineStyleSingle
> .ColorIndex = 5
> End With
> End Sub
>
>
> Max wrote:
> > Hi!
> >
> > I'm using the following code to try and create automatic HyperLinks in my
> > workbook:
> >
> > Sheet2.Cells(i + 5, 2).Value = strENGINE
> > Sheet2.Cells(i + 5, 2).Select
> > ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
> > "'" & strENGINE & "'!A1", TextToDisplay:=strENGINE
> > With Selection.Font
> > .Name = "Arial"
> > .FontStyle = "Regular"
> > .Size = 14
> > .Strikethrough = False
> > .Superscript = False
> > .Subscript = False
> > .OutlineFont = False
> > .Shadow = False
> > .Underline = xlUnderlineStyleSingle
> > .ColorIndex = 5
> > End With
> >
> > where strENGINE is the name of a worksheet in the same workbook. However,
> > when I click on the created link, I get a "Reference is not valid." error.
> > What can I do to correct this?
> >
> > Note, strENGINE may contain a hypen in it - does this cause issues as well?
> > --
> > Thanks!
> > Max


 
Reply With Quote
 
Dennis
Guest
Posts: n/a
 
      14th Nov 2006
Forgot the final "+" sign in:

"'" + Sheets(2).Cells(i + 5, 2).Value + "'!"

GL EagleOne

 
Reply With Quote
 
=?Utf-8?B?TWF4?=
Guest
Posts: n/a
 
      15th Nov 2006
Thanks for the help!

I made the suggested changes - and really, it's a matter of preference...
But I'm still getting errors.

Yes, strENGINE is a variable that is previously used to name a sheet. When
I run, no erros. But when I try and click the hyperlink, I get the following
error:

"Your formula contains an invalid external reference to a worksheet. Verify
that the path, workbook, and range name or cell reference are correct, and
try again."

Here's the kicker, when I just insert a hyperlink, the path that it
generates and displays when I hover over the link is EXACTLY THE SAME!!!
What am I missing?

Here's what I have now:

Sheets(2).Cells(i + 5, 2).Value = strENGINE
Sheets(2).Cells(i + 5, 2).Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
"'" + Sheets(2).Cells(i + 5, 2).Value + "'!",
TextToDisplay:=Sheets(2).Cells(i + 5, 2).Value
With Cells(i + 5, 2).Font
.Name = "GE Inspira"
.FontStyle = "Regular"
.Size = 14
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = True
.Underline = xlUnderlineStyleSingle
.ColorIndex = 5
End With

--
Thanks!
Max


"Dennis" wrote:

> Forgot the final "+" sign in:
>
> "'" + Sheets(2).Cells(i + 5, 2).Value + "'!"
>
> GL EagleOne
>
>

 
Reply With Quote
 
acampbell
Guest
Posts: n/a
 
      16th Nov 2006
Max,

I looked at your code again. Below is a revision to what I posted
previously. As I mentioned before, Ignore the mods. I put in for
testing. Your link as coded produces the following (on my machine),
resulting in the reference error.

\\\C:\My documents\VBA Projects\Book1.xls - strENGINE! - Click once
to...

I modified code per below which links to cell A1 on sheet strENGINE.

\\\C:\My documents\VBA Projects\Book1.xls - strENGINE!A1 - Click once
to...

Max wrote:
> Thanks for the help!
>
> I made the suggested changes - and really, it's a matter of preference...
> But I'm still getting errors.
>
> Yes, strENGINE is a variable that is previously used to name a sheet. When
> I run, no erros. But when I try and click the hyperlink, I get the following
> error:
>
> "Your formula contains an invalid external reference to a worksheet. Verify
> that the path, workbook, and range name or cell reference are correct, and
> try again."
>
> Here's the kicker, when I just insert a hyperlink, the path that it
> generates and displays when I hover over the link is EXACTLY THE SAME!!!
> What am I missing?
>
> Here's what I have now:
>
> Sheets(2).Cells(i + 5, 2).Value = strENGINE
> Sheets(2).Cells(i + 5, 2).Select
> ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
> "'" + Sheets(2).Cells(i + 5, 2).Value + "'!",
> TextToDisplay:=Sheets(2).Cells(i + 5, 2).Value
> With Cells(i + 5, 2).Font
> .Name = "GE Inspira"
> .FontStyle = "Regular"
> .Size = 14
> .Strikethrough = False
> .Superscript = False
> .Subscript = False
> .OutlineFont = False
> .Shadow = True
> .Underline = xlUnderlineStyleSingle
> .ColorIndex = 5
> End With
>
> --
> Thanks!
> Max
>
>
> "Dennis" wrote:
>
> > Forgot the final "+" sign in:
> >
> > "'" + Sheets(2).Cells(i + 5, 2).Value + "'!"
> >
> > GL EagleOne
> >
> >


 
Reply With Quote
 
acampbell
Guest
Posts: n/a
 
      16th Nov 2006
Max,

Sorry. I meant to post the code as well.

Alan

Sub test5()
Dim strEngine
Dim i
i = 4
Sheets(2).Cells(i + 5, 2).Value = "strEngine"
Sheets(2).Cells(i + 5, 2).Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="",
SubAddress:= _
"'" + Sheets(2).Cells(i + 5, 2).Value + "'!A1", _ '<<<<<<
Inserted Cell reference.
TextToDisplay:=Sheets(2).Cells(i + 5, 2).Value
With Cells(i + 5, 2).Font
.Name = "GE Inspira"
.FontStyle = "Regular"
.Size = 14
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = True
.Underline = xlUnderlineStyleSingle
.ColorIndex = 5
End With
End Sub


Max wrote:
> Thanks for the help!
>
> I made the suggested changes - and really, it's a matter of preference...
> But I'm still getting errors.
>
> Yes, strENGINE is a variable that is previously used to name a sheet. When
> I run, no erros. But when I try and click the hyperlink, I get the following
> error:
>
> "Your formula contains an invalid external reference to a worksheet. Verify
> that the path, workbook, and range name or cell reference are correct, and
> try again."
>
> Here's the kicker, when I just insert a hyperlink, the path that it
> generates and displays when I hover over the link is EXACTLY THE SAME!!!
> What am I missing?
>
> Here's what I have now:
>
> Sheets(2).Cells(i + 5, 2).Value = strENGINE
> Sheets(2).Cells(i + 5, 2).Select
> ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
> "'" + Sheets(2).Cells(i + 5, 2).Value + "'!",
> TextToDisplay:=Sheets(2).Cells(i + 5, 2).Value
> With Cells(i + 5, 2).Font
> .Name = "GE Inspira"
> .FontStyle = "Regular"
> .Size = 14
> .Strikethrough = False
> .Superscript = False
> .Subscript = False
> .OutlineFont = False
> .Shadow = True
> .Underline = xlUnderlineStyleSingle
> .ColorIndex = 5
> End With
>
> --
> Thanks!
> Max
>
>
> "Dennis" wrote:
>
> > Forgot the final "+" sign in:
> >
> > "'" + Sheets(2).Cells(i + 5, 2).Value + "'!"
> >
> > GL EagleOne
> >
> >


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: creating hyperlinks stew Microsoft Excel Misc 0 21st Dec 2008 06:08 PM
Re: creating hyperlinks Dave Peterson Microsoft Excel Misc 0 21st Dec 2008 02:37 PM
Creating hyperlinks Fred Microsoft Excel Misc 0 21st Feb 2007 03:13 PM
Creating Hyperlinks =?Utf-8?B?S2lt?= Microsoft Frontpage 3 5th Sep 2006 01:25 PM
Creating a PDF from a PPT with Hyperlinks =?Utf-8?B?UGV0ZQ==?= Microsoft Powerpoint 2 12th Sep 2005 08:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:54 PM.