Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2464
  • Last Modified:

Create a hyperlink from selected cell using VBA

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
AndreasHermle
Asked:
AndreasHermle
2 Solutions
 
[ fanpages ]IT Services ConsultantCommented:
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
 
NorieCommented:
Replace Excel.Selection with ActiveCell.Offset(,1).
0
 
AndreasHermleAuthor Commented:
Dear Experts:

both codes work just fine.

Thank you very much for your great help.

Regards, andreas
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now