Invoke hyperlink

  • Thread starter Thread starter DKS
  • Start date Start date
D

DKS

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?
 
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?
 
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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top