E
EdwardSF
Beth Melton suggested that I bring my question here from the Word Application
Errors board, as it involves some VBA programming.
I work in a transcription office, with several stand-alone computers hooked
through a router to a server. After typing a report, we run a macro I wrote
to add a line to a table in a document on the server called UCSFLOG.doc.
The problem is, every now and then (but with increasing frequency over the
past couple of weeks) the log file just disappears, without a trace. Not in
the Recycle Bin, not anywhere on the server or any of the computers in the
office. Poof.
The macro in question contains a loop where, if there's an error opening the
log file it'll display a MsgBox, then go back and try again. This was put in
place when the boss would open the log file to look at and leave it up on her
computer; now it's meant to catch the event where the log disappears
completely.
However, when the log file does its disappearing act, the MsgBox never comes
up; instead, Word displays its own error message, asking to reconnect to the
network (the connection is still up at this point) or insert a floppy disk.
This message is caught in an infinite loop, so you have to CTRL-ALT-DEL and
restart Word. When restarting Word, it can't recover the log file, even
though there's a copy of it in a TMP file.
So, it *looks* like the macro is opening the log file without a problem;
then when it goes to save it again it creates a TMP file, removes the
original, and then freaks out when it can't find it on the drive. Beth
suggested that this could happen when more than one person is running the
macro, but A) the error-handling loop ought to catch that, and 2) it's
happened when nobody else is even working in Word.
I can't see how anything I wrote in the macro could cause this, but
otherwise I'm stumped. I confess to being just a gifted amateur with VBA, so
feel free to rip me for doing something heinously wrong. The pertinent code
is below. Thanks.
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. It looks like the Word error message comes up
at this point.
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
Errors board, as it involves some VBA programming.
I work in a transcription office, with several stand-alone computers hooked
through a router to a server. After typing a report, we run a macro I wrote
to add a line to a table in a document on the server called UCSFLOG.doc.
The problem is, every now and then (but with increasing frequency over the
past couple of weeks) the log file just disappears, without a trace. Not in
the Recycle Bin, not anywhere on the server or any of the computers in the
office. Poof.
The macro in question contains a loop where, if there's an error opening the
log file it'll display a MsgBox, then go back and try again. This was put in
place when the boss would open the log file to look at and leave it up on her
computer; now it's meant to catch the event where the log disappears
completely.
However, when the log file does its disappearing act, the MsgBox never comes
up; instead, Word displays its own error message, asking to reconnect to the
network (the connection is still up at this point) or insert a floppy disk.
This message is caught in an infinite loop, so you have to CTRL-ALT-DEL and
restart Word. When restarting Word, it can't recover the log file, even
though there's a copy of it in a TMP file.
So, it *looks* like the macro is opening the log file without a problem;
then when it goes to save it again it creates a TMP file, removes the
original, and then freaks out when it can't find it on the drive. Beth
suggested that this could happen when more than one person is running the
macro, but A) the error-handling loop ought to catch that, and 2) it's
happened when nobody else is even working in Word.
I can't see how anything I wrote in the macro could cause this, but
otherwise I'm stumped. I confess to being just a gifted amateur with VBA, so
feel free to rip me for doing something heinously wrong. The pertinent code
is below. Thanks.
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. It looks like the Word error message comes up
at this point.
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