Hi, all!
I am attempting to build a workbook for use by our HR director. In the section I'm working on now, I'm trying to create a macro to do the following:
- Allow user to enter New Employee name into an Input Box
- Create a new worksheet using the New Employee name as the
Sheet Name
- Add the New Employee name to the Directory page
- Add a hyperlink to the cell on the Directory Page that will jump to the
New Employee name sheet that was just created.
Most of my macro is working great! My input box comes up, creates and renames a new sheet, and adds the name to the directory page.
However, when it comes to creating the hyperlink, I have the following line of code in my macro:
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", _
SubAddress:= "'NewName'!A1", TextToDisplay:=NewName
(NewName is the name of my variable)
When I try to click the hyperlink, I get a "Reference is not valid" error. I got the code by recording a macro that creates a hyperlink, then changed the subaddress and texttodisplay fields to use my variable name.
I'm thinking this should be something simple to fix, but I've tried all kinds of variations on the above code (including changing the macro so the sheet is created before the hyperlink!), and can't seem to get it right.
Can anyone help me? Thanks so much!
I am attempting to build a workbook for use by our HR director. In the section I'm working on now, I'm trying to create a macro to do the following:
- Allow user to enter New Employee name into an Input Box
- Create a new worksheet using the New Employee name as the
Sheet Name
- Add the New Employee name to the Directory page
- Add a hyperlink to the cell on the Directory Page that will jump to the
New Employee name sheet that was just created.
Most of my macro is working great! My input box comes up, creates and renames a new sheet, and adds the name to the directory page.
However, when it comes to creating the hyperlink, I have the following line of code in my macro:
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", _
SubAddress:= "'NewName'!A1", TextToDisplay:=NewName
(NewName is the name of my variable)
When I try to click the hyperlink, I get a "Reference is not valid" error. I got the code by recording a macro that creates a hyperlink, then changed the subaddress and texttodisplay fields to use my variable name.
I'm thinking this should be something simple to fix, but I've tried all kinds of variations on the above code (including changing the macro so the sheet is created before the hyperlink!), and can't seem to get it right.
Can anyone help me? Thanks so much!