Hyperlink problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I made a text box that contains the address of a file on a shared drive. I
also made a button thats supposed to open up the file. when i press the
button, i get an error saying that it can't follow the hyperllink "File
name". it highlights the .follow part of the form.

Sub CreateHyperlink(ctlSelected As Control, _
strSubAddress As String, Optional strAddress As String)
Dim hlk As Hyperlink
Select Case ctlSelected.ControlType
Case acLabel, acImage, acCommandButton
Set hlk = ctlSelected.Hyperlink
With hlk
If Not IsMissing(strAddress) Then
.Address = strAddress
Else
.Address = ""
End If
.SubAddress = strSubAddress
.Follow
.Address = ""
.SubAddress = ""
End With
Case Else
MsgBox "The control '" & ctlSelected.Name _
& "' does not support hyperlinks."
End Select
End Sub
 
If you have a filespec (e.g "M:\Folder\Sub folder\File name.doc") in a
textbox txtFileSpec, all you need is

Application.FollowHyperlink Me.txtFileSpec.Value

There's no need to muck round with the Hyperlink property of other
controls.
 
Back
Top