I used to have a function "boolDocIsOpen", in fact I still do, with gazillions of calls to it in all sorts of templates (mostly locked) on all sorts of drives..

I've re-written "boolDocIsOpen" today as part of my plan to stop a template-processing application closing itself when it has been swept up in a scan of all templates.

I thought that a test after processing each template "do not close this template if it is yourself" would do the trick, but the problem went deeper than that.

Tuns out that my test for a document being open - providing the full name OR the local name and testing against the local name in the Documents collection wasn't good enough.

I have to test the full name each time, since I can have a Procs098.dot in Spare and another Procs098.dot in Temp and another Procs098.dot in UserTemplates and so on.

Of course, it would be nice if I could just replace all calls to boolDocIsOpen with calls to boolFULLDocIsOpen, but that won't work, because many of my calls employ just the local file name (I was young and innocent back then!).

So now I'm wrestling with how to make an interim measure work.

What if I test in boolFULLDocIsOpen for the presence of a ":" and/or a "". If at least one of each is present, then presumably I was given a full name; but if either is absent, then how can I be sure that I am testing the correct file? I think I cannot. If I ask you about "Procs098.dot", you have to ask me "WHICH Procs098.dot?", and I can't tell you if I don't have the drivepath.


Bottom line seems to me to be that I am saddled with a lot of faulty code, penalty of a mis-spent VBA youth, and I ought to go back and locate every call to "boolDocIsOpen", replace it with a call to "boolFULLDocIsOpen", and make sure that each such call is using a full drivepathfile name.



I'm not looking forward to this.



I suppose I could test for ":" and/or"/" and stop dead (with an error message) the first time I trap such an error. Seems klutzy, frankly.

"I could use a few suggestions", he said sadly, his voice dropping a semi-tone and growing faint .....




<pre>Public Function boolFULLDocIsOpen(strFullName As String)
' Procedure : boolFULLDocIsOpen
' Description:
' Copyright: Chris Greaves Inc.
' Inputs: STRING Full name (drivepathname.ext) of a file
' Returns: TRUE if file is alreday open as a document
' Assumes: Nothing
' Side Effects: None.
' Tested: By the calls shown below.
boolFULLDocIsOpen = False
If strFullName = "" Then
Else
Dim doc As Document
For Each doc In Documents
If UCase(doc.FullName) = UCase(strFullName) Then
boolFULLDocIsOpen = True
Exit For
Else
End If
Next doc
End If
'Sub TESTboolFULLDocIsOpen()
' MsgBox boolFULLDocIsOpen(MacroContainer.Name) ' FALSE
' MsgBox boolFULLDocIsOpen(MacroContainer) ' FALSE
' MsgBox boolFULLDocIsOpen("d:greavestrainingwordprocessing word97startupspare" _
& MacroContainer.Name) ' FALSE
' MsgBox boolFULLDocIsOpen(MacroContainer.Path & Application.PathSeparator_
& MacroContainer.Name) ' TRUE
'End Sub
End Function
</pre>