The problem is becoming more frequent; three times now in two weeks.
On none
of the occasions was anybody else accessing the file in question; on
one
occasion no one else was even using Word.
The pertinent code is below. There is an error-handling routine for
when
there is a problem opening the log file. (Our boss would open the
log and
leave it up on her computer, forcing everybody else to open a
read-only copy.
This was later changed to try to capture the missing-log event.)
When the
log disappears, though, the "don't panic" message I wrote never
comes up;
instead, Word displays its own error message that it can't find the
file, and
to either reconnect to the network or insert a floppy disk
[RETRY/CANCEL].
Sure enough, there is a TMP file with the log in it (but not the
current
entry), but the file itself has disappeared.
(Interestingly, the Word error message is caught in an infinite
loop;
neither RETRY nor CANCEL closes the box. You have to CTRL-ALT-DEL
and
restart Word. At which time you can recover the document you were
working
on, but Word can't recover the UCSFLOG file, even though there's a
TMP file
on the drive.)
So I think you're right, Beth; it *seems* that the macro is opening
the log
file without a problem, makes a TMP file, removes the original and
then
freaks out when it can't find it. What baffles me is why this is
happening
even when there's only one person in the office running the macro,
or even
using Word at all.
CODE:
'
' Some data-parsing stuff here
' Then it saves the current document for sending to the client.
(They want
the file
' names a certain way.)
ChangeFileOpenDirectory "F:\CL\UCSFSEND\"
varFileName = "7" + varDocType + varFacNum + Right$(varJobID, 4)
+ "." +
varTransID
ActiveDocument.SaveAs FileName:=varFileName + ".doc"
' Next an entry is made into a table in a document called
UCSFLOG.doc.
This is the Amazing Disappearing File.
' Sometimes the boss opens the file to get statistics, and leaves
the file
open. Then if
' someone runs the macro, they get an error message that the file
is
already open. This
' next block of code originally meant to deal with that, so the
user could
go tell the boss
' to close the file then try again, without the macro bombing out.
Later,
when the
' UCSFLOG file started disappearing entirely, the MsgBox message
was more
strongly
' worded, but the loop was left in place.
ChangeFileOpenDirectory "F:\CL\UCSF"
TryOpen:
On Error Resume Next
Documents.Open FileName:="UCSFLOG.doc"
varError = Err.Number
If varError <> 0 Then
MsgBox ("UCSFLOG cannot be found. Something has gone
seriously
wrong. Do not panic.")
GoTo TryOpen
End If
' Once the UCSFLOG file has been closed elsewhere (and assuming
that it's
still on the server at this point), a line is added to the table.
' Now, we save the UCSFLOG file, as well as (recently added) a
backup copy
on an
' entirely separate drive.
ActiveDocument.SaveAs
ChangeFileOpenDirectory "Z:\"
ActiveDocument.SaveAs ("UCSFLOGbackup.doc")
ChangeFileOpenDirectory "F:\CL\UCSF"
ActiveDocument.Close
' Close the report as well
ActiveDocument.Close Savechanges:=wdSaveChanges
End Sub
Beth Melton said:
First we'd have to see the macro in order to understand what it's
doing.
Second, I suspect the file is there but as a temp file. If you are
repeatedly opening/saving/closing the file then it's possible the
macro attempts to run again during the save process. When a
document
is saved a temp file is created, the original document is deleted,
and
the temp file is renamed to take the place of the original file. So
if
macro attempts to run at precisely the right point, in between the
deletion of the original and rename of the temp file, then there
will
not be a document to open, and it crashes. Since the save process
can
not be completed then the temp file is never renamed.
Check the folder where the original document is stored and see if
there are any temp files. More than likely they will be named
something like: ~wrd*.tmp. If you can open them in Word and if it
is
indeed the missing document then I'd say what I described above is
the
problem. To correct it I'd suggest that you head over to one of the
VBA newsgroups and see if someone there can help you modify the
macro
so it will first check to see if the file exists and if it doesn't
add
a wait/delay routine and then check for its existence again.
Please post all follow-up questions to the newsgroup. Requests for
assistance by email can not be acknowledged.
~~~~~~~~~~~~~~~
Beth Melton
Microsoft Office MVP
TechTrax eZine:
http://mousetrax.com/techtrax/
MVP FAQ site:
http://mvps.org/