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