Solved

Create a hyperlink from selected cell using VBA

Posted on 2013-05-27
3
1,609 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
Comment Utility
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
Comment Utility
Replace Excel.Selection with ActiveCell.Offset(,1).
0
 

Author Closing Comment

by:AndreasHermle
Comment Utility
Dear Experts:

both codes work just fine.

Thank you very much for your great help.

Regards, andreas
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now