View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Invoke hyperlink


But at this point I have another question:
if the string expression does not contain a valid url then how can we trap
this error programatically?


If you want to check the URL for syntactic validity, but not whether the URL
actually exists on the network, you can use a function like the following.
This will return TRUE if the URL is properly formed but does not test
whether it is an existing, accessible, location.

Function IsValidURL(URL As String) As Boolean
Dim RegExp As Object
Dim S As String
If StrComp(Left(URL, 4), "http", vbTextCompare) < 0 Then
S = "http://" & URL
Else
S = URL
End If
Set RegExp = CreateObject("vbscript.regexp")
RegExp.Pattern =
"^(http|https)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)" & _
"?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&amp;%\$#\=~])*[^\.\,\)\(\s]$"
IsValidURL = RegExp.test(S)
End Function



--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2008
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


"DKS" wrote in message
...
Got it:

ActiveWorkbook.followhyperlink <string expression where string expression
must contain a valid URL.

But at this point I have another question:
if the string expression does not contain a valid url then how can we trap
this error programatically? i noticed that due to a bug in some case my
string expression did not contain a valid url, and despite having an ON
ERROR
clause the routine did not trap the error. Any ideas?

"DKS" wrote:

in a module i have created a valid url address in a text field. I want
to
"Follow" the created url. What is the best way to achieve that?