M
Mike NG
In relation to my thread yesterday "Waiting for a specific named
document to close" I have the following code
<standard automation>
On Error GoTo dun
Do Until lbDone
DoEvents
lbDone = True
With loWord
For liLoop = 1 To loWord.Documents.Count
If loWord.Documents(liLoop).Name = lsDocName Then
lbDone = False
Exit For
End If
Next
End With
Loop
dun:
Set loWord = Nothing
I need to know how the loop was exited - i.e. was it word closing, or
the document being closed. I could use another boolean which I set to
True and the same time as setting lbDone to False, but I'd like to just
know what the condition should be on loWord as I believe this should be
possible. I noticed from the debugger that whilst Word is active,
loWord has a value something like "Microsoft Word" and if it was closed
it will have a value of Nothing. Is this the right approach or should I
be testing something else
I have seen this kind of code for latching onto an already open Word
object which would also do the trick but I feel I should be able to put
something in my loop
On Error Resume Next
Set loWord = GetObject(, "Word.Application")
If Err Then
'No, word is not running
Err.Clear
End If
document to close" I have the following code
<standard automation>
On Error GoTo dun
Do Until lbDone
DoEvents
lbDone = True
With loWord
For liLoop = 1 To loWord.Documents.Count
If loWord.Documents(liLoop).Name = lsDocName Then
lbDone = False
Exit For
End If
Next
End With
Loop
dun:
Set loWord = Nothing
I need to know how the loop was exited - i.e. was it word closing, or
the document being closed. I could use another boolean which I set to
True and the same time as setting lbDone to False, but I'd like to just
know what the condition should be on loWord as I believe this should be
possible. I noticed from the debugger that whilst Word is active,
loWord has a value something like "Microsoft Word" and if it was closed
it will have a value of Nothing. Is this the right approach or should I
be testing something else
I have seen this kind of code for latching onto an already open Word
object which would also do the trick but I feel I should be able to put
something in my loop
On Error Resume Next
Set loWord = GetObject(, "Word.Application")
If Err Then
'No, word is not running
Err.Clear
End If