Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do I create a hyperlink with a macro?

Hello,

I am attempting to create a spread sheet for work that is as easy to use as
possible. My goal is to create a macro that adds a hyperlink to a particular
cell. The catch is, I would like the URL to come from the clipboard. This way
all they need to do is copy the address and run the macro. Is this possible?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default How do I create a hyperlink with a macro?

Hope this helps... You can paste link copied from clipboard into an inputbox...

Sub add_hyperlink()

Dim hl As String
hl = InputBox("Copy link he")
If Len(hl) = 0 Then Exit Sub
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
"http://www.microsoft.com", ScreenTip:="Goto Microsoft's site", _
TextToDisplay:="Microsoft"
End Sub

--
Regards,
Anant


"jimmulv3" wrote:

Hello,

I am attempting to create a spread sheet for work that is as easy to use as
possible. My goal is to create a macro that adds a hyperlink to a particular
cell. The catch is, I would like the URL to come from the clipboard. This way
all they need to do is copy the address and run the macro. Is this possible?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default How do I create a hyperlink with a macro?

Sub add_hyperlink()

Dim hl As String
hl = InputBox("Copy link he")
If Len(hl) = 0 Then Exit Sub
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
hl, ScreenTip:="Goto Microsoft's site", _
TextToDisplay:="Microsoft"
End Sub

sorry!! forgot to replace variable in the last post...
--
Regards,
Anant


"Anant Basant" wrote:

Hope this helps... You can paste link copied from clipboard into an inputbox...

Sub add_hyperlink()

Dim hl As String
hl = InputBox("Copy link he")
If Len(hl) = 0 Then Exit Sub
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
"http://www.microsoft.com", ScreenTip:="Goto Microsoft's site", _
TextToDisplay:="Microsoft"
End Sub

--
Regards,
Anant


"jimmulv3" wrote:

Hello,

I am attempting to create a spread sheet for work that is as easy to use as
possible. My goal is to create a macro that adds a hyperlink to a particular
cell. The catch is, I would like the URL to come from the clipboard. This way
all they need to do is copy the address and run the macro. Is this possible?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How do I create a hyperlink with a macro?

First, Chip Pearson explains how to get text off the clipboard he
http://www.cpearson.com/excel/Clipboard.aspx

Read his notes carefully. There's a warning about setting a reference to
Microsoft Forms 2.0 Object Library that you need to do.

This modified version of his sample code worked ok for me:

Option Explicit
Sub testme()

Dim DataObj As MSForms.DataObject
Dim myStr As String
Dim myCell As Range

Set DataObj = New MSForms.DataObject

DataObj.GetFromClipboard
myStr = DataObj.GetText

'check for a leading HTTP:
If UCase(Left(myStr, 5)) = UCase("http:") Then
'some cell
Set myCell = ActiveSheet.Range("A3")

'pesky spaces???
myStr = Replace(myStr, " ", "%20")

'=hyperlink() formula style of hyperlink
myCell.Formula = "=hyperlink(""" & myStr & """,""click me"")"

'or Insert|Hyperlink style
myCell.Hyperlinks.Add anchor:=myCell, _
Address:=myStr, TextToDisplay:=myStr

End If

End Sub

========
You can have two different styles of hyperlinks in excel -- the =hyperlink()
version and the Insert|Hyperlink (ctrl-k) version.

Personally, I find the =hyperlink() worksheet formula much nicer behaved.

But don't use both. Delete one of them from the code (or comment it out).

jimmulv3 wrote:

Hello,

I am attempting to create a spread sheet for work that is as easy to use as
possible. My goal is to create a macro that adds a hyperlink to a particular
cell. The catch is, I would like the URL to come from the clipboard. This way
all they need to do is copy the address and run the macro. Is this possible?


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to create hyperlink JoeP Excel Programming 3 September 5th 09 11:40 AM
HELP to program a macro to create a hyperlink Nemo69 Excel Programming 0 February 20th 09 12:51 PM
Create a Hyperlink as part of a macro Nahraine New Users to Excel 1 March 7th 07 04:37 PM
Macro To Create Hyperlink from html text Ketan Patel Excel Programming 1 September 6th 05 05:03 PM
Create a HYPERLINK with a macro? bobgerman[_3_] Excel Programming 2 December 22nd 03 06:41 PM


All times are GMT +1. The time now is 03:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"