Hyperlink to Word opens a copy

  • Thread starter Thread starter Steve A
  • Start date Start date
S

Steve A

I am using a Hyperlink on a form to open a calendar that
was created in Word and is on a shared drive. Sometimes
the user needs the original file to make updates, but if
the file is already open, the hyperlink just opens a
copy. The user does not get a warning that the file is
already open along with an option of creating a copy.
Opening the file directly in Word (or from Windows
Explorer) when someone else already has it open gets the
expected dialog box indicating that the file is already
open. My hyperlink address looks like this
P:\Clec\Clec Calendar\2003 Calendar.doc
Any thoughts?
 
Steve A said:
I am using a Hyperlink on a form to open a calendar that
was created in Word and is on a shared drive. Sometimes
the user needs the original file to make updates, but if
the file is already open, the hyperlink just opens a
copy. The user does not get a warning that the file is
already open along with an option of creating a copy.
Opening the file directly in Word (or from Windows
Explorer) when someone else already has it open gets the
expected dialog box indicating that the file is already
open. My hyperlink address looks like this
P:\Clec\Clec Calendar\2003 Calendar.doc
Hi Steve,

One possibility (untested) would be to save the following
code in a module from
http://support.microsoft.com/default.aspx?scid=kb;EN-US;213383


'*** code start and QUOTE ********
Public Function IsFileOpen(filename As String)
Dim filenum As Integer, errnum As Integer

On Error Resume Next ' Turn error checking off.
filenum = FreeFile() ' Get a free file number.
' Attempt to open the file and lock it.
Open filename For Input Lock Read As #filenum
Close filenum ' Close the file.
errnum = Err ' Save the error number that occurred.
On Error GoTo 0 ' Turn error checking back on.

' Check to see which error occurred.
Select Case errnum

' No error occurred.
' File is NOT already open by another user.
Case 0
IsFileOpen = False

' Error number for "Permission Denied."
' File is already opened by another user.
Case 70
IsFileOpen = True

' Another error occurred.
Case Else
Error errnum
End Select

End Function
'*** end code and QUOTE ***


Then rethink your hyperlink label
on your form (say it were "Label15").
Cut your link from HyperLink Address
and paste in Caption. Set borders and
back style to Transparent. Since no longer
have HyperLink Address property, set color
of font and underline to look like hyperlink.

Use the following code for the Click event
of your "Label15"


Private Sub Label15_Click()
Dim varResponse As Variant
If IsFileOpen(Me!Label15.Caption) Then
varResponse = MsgBox("File is already open. " _
& vbCrLf & "Would you like to open a copy of the file?", vbYesNo)
If varResponse = vbYes Then
Application.FollowHyperlink Me!Label15.Caption
Else
Exit Sub
End If
Else
Application.FollowHyperlink Me!Label15.Caption
End If
End Sub


Please respond back if I have misunderstood.

Good luck,

Gary Walter
 
Back
Top