Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Create a hyperlink from selected cell using VBA

Posted on 2013-05-27
3
1,831 Views
Last Modified: 2013-05-28
Dear Experts:

below macro converts the selected cell (containing a file path)  into a hyperlink. How does this code have to be re-written so that the hyperlink is created in the cell next to the selected cell so that the initially selected cell is not changed

Example:

Cell A1: C:\test\myfile.xls

After running the macro the sheet looks like this:
Cell A1: C:\test\myfile.xls
Cell B1: C:\test\myfile.xls (converted into a hyperlink)

Help is much appreciated. Thank you very much in advance.

Regards, Andreas

Sub ConvertToHyperlink()
    ActiveSheet.Hyperlinks.Add Anchor:=Excel.Selection, Address:= _
        ActiveCell.Value, TextToDisplay:=ActiveCell.Value
End Sub

Open in new window

0
Comment
Question by:AndreasHermle
3 Comments
 
LVL 35

Assisted Solution

by:[ fanpages ]
[ fanpages ] earned 250 total points
ID: 39199346
Hi Andreas,

Please try this:

Sub ConvertToHyperlink()

    ActiveSheet.Hyperlinks.Add Anchor:=Excel.Selection.Offset(,1), Address:=ActiveCell.Value, TextToDisplay:=ActiveCell.Value

End Sub

Open in new window


BFN,

fp.
0
 
LVL 33

Accepted Solution

by:
Norie earned 250 total points
ID: 39199576
Replace Excel.Selection with ActiveCell.Offset(,1).
0
 

Author Closing Comment

by:AndreasHermle
ID: 39202234
Dear Experts:

both codes work just fine.

Thank you very much for your great help.

Regards, andreas
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question