Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Figuring out hyperlink in a cell with a macro in VBA

Hi,
I am in a desperate need of help. Can anyone let me know how to find
out a cell that contains a hyperlink. I mean we can figure out formula
by hasFormula function. How can we find for a hyperlink. Please help,
Nasir.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Figuring out hyperlink in a cell with a macro in VBA


Hello Nasir,

There is no built-in Excel worksheet function to test if a cell
contains a hyperlink. The following macro code is for a User Defined
Function that will test a cell for a hyperlink and return either True
or False.

Copy this code, add a VBA module to your Workbook, and paste the code
into the module.

Cell Formula...

=HasHyperlink(B50)

If B50 contains a Hyperlink the cell with the Formula will be TRUE,
otherwise FALSE.


Code:
--------------------
Function HasHyperlink(Cell_Address As Range) As Boolean

Application.Volatile

Dim I As Long
Dim LinkRng As Range
Dim Wks As Worksheet
Dim X As Range

Set Wks = ThisWorkbook.Worksheets(Cell_Address.Parent.Name)
Lnks = Wks.Hyperlinks.Count

If Lnks 0 Then
With Wks.Hyperlinks
Set LinkRng = .Item(1).Range
For I = 1 To Lnks
Set LinkRng = Application.Union(LinkRng, .Item(I).Range)
Next I
End With
End If

Set X = Application.Intersect(Cell_Address, LinkRng)

If X Is Nothing Then
HasHyperlink = False
Else
HasHyperlink = True
End If

End Function

--------------------


Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=553913

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
Need help figuring out how to code this macro jefals Excel Worksheet Functions 4 September 30th 07 01:50 AM
How to determine within a macro if a cell contains a hyperlink. Richard L. Miga Excel Discussion (Misc queries) 4 May 8th 07 12:32 PM
How to hyperlink a macro from a cell rhhince Excel Worksheet Functions 1 December 25th 06 08:58 PM
Excell- am stupid and need help figuring out how to write in cell jenkinsville Excel Discussion (Misc queries) 2 September 9th 06 07:45 PM
Can a macro create a hyperlink with unique cell information? Desiree Excel Programming 3 October 22nd 04 07:49 PM


All times are GMT +1. The time now is 05:03 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"