0

I want a method to create a hyperlink of some variable in excel macro. My requirement is I have to capture a link in some variable for ex:

abc = InputBox("Enter the path")

now I want to use this abc as a parameter to a hyperlink function and create a hyperlink with name xyz. Can you help me to solve this issue?

1
  • Refer to this MSDN KB Commented Jan 27, 2016 at 13:25

2 Answers 2

1

OK, here is the code. What it is doing is 1. Asking what URL you want 2. Storing the URL in a variable called URL 3. Going to Sheet 1, adding the hyperlink function to cell A5, linking it to the URL you input 4. Displaying the friendly name you give it in the code

Let me know if you have any questions | you will just need to modify the code for the URL you want or place the links where you want.

Tested and working. Please vote as answer :)

Sub CreateHyperLink()
Dim URL As String
URL = InputBox("Enter the link")
With Worksheets("Sheet1")
.Hyperlinks.Add Anchor:=.Range("A5"), _
Address:="http://www." & URL, _
TextToDisplay:="Google"
End With
End Sub
Sign up to request clarification or add additional context in comments.

4 Comments

1. abc = InputBox("Enter the link") 2. A = "=Hyperlink(abc, ""friendlyname"")" 3. wb2.Sheets("Rest").Range("A" & restcounter) = A this is what i want. i want to get the link(ex. www.google.com) as input. then i want to create a hyperlink and store it some variable A, then i paste the value in some cell of a excel sheet. please provide me the solution or best approach to solve this issue.
Edited my answer from this morning. Code is tested and working. Let me know.
i have some other doubt too..i hope you can help me. how can i contact you?
Nelsons Development Solutions @gmail . com no spaces
0

Use the HYPERLINK function:

=HYPERLINK(link_location, friendly_name)

Creates a shortcut or jump that opens a document stored on your hard drive, a network server, or on the Internet.

For example in macro code:

Worksheets("Sheet1").Range("A1").Formula = "=HYPERLINK(""" & link_destination & """,""" & link_text & """)"

Note the use of "" (two double quotes) in the VBA code to produce a single double quote in the cell formula.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.