Solved

Create a hyperlink from selected cell using VBA

Posted on 2013-05-27
3
2,111 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
[X]
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
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 34

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

624 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