MartyConnelly
martyconnelly at shaw.ca
Fri Jan 23 17:05:53 CST 2004
Debug.Print IsFileOpen("C:\Documents and Settings\marty\My Documents\Doc1.doc") ' This function checks to see if a file is open or not. If the file is ' already open, it returns True. If the file is not open, it returns ' False. Otherwise, a run-time error will occur because there is ' some other problem accessing the file. Function IsFileOpen(filename As String) As Boolean 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 rusty.hammond at cpiqpc.com wrote: >I'm working on code in Access 97 to simply open an existing Word document >from a network drive, add a quick line of text at the top of the first page, >then close the document. I'm running into problems when someone else has >the Word document open. Does anyone have code to tell if a Word document is >open before attempting to open it and getting an error? > >TIA > >Rusty Hammond > > > -- Marty Connelly Victoria, B.C. Canada