G
George Lee
How do you check if a reference is still valid? For example, if at the time
you need to use a another document reference, how can you check that it’s
still valid?
Dim sourceDocument as document
Set sourceDocument = documents.add
…
If not sourceDocument is nothing then …
Here, the sourceDocument may have been closed before the last call, but in
checking the the reference, sourceDocument isn’t nothing (it’s still looks
valid), isn’t null (not really used much in VBA anyhow), or empty (it’s been
allocated at some point). Currently, I am forcing an error:
On Error Resume Next
Dim dummyString as string
dummyString = sourceDocument.Name
If Err.Number = 462 Then
Set sourceDocument = Nothing
End If
Is there a better way?
you need to use a another document reference, how can you check that it’s
still valid?
Dim sourceDocument as document
Set sourceDocument = documents.add
…
If not sourceDocument is nothing then …
Here, the sourceDocument may have been closed before the last call, but in
checking the the reference, sourceDocument isn’t nothing (it’s still looks
valid), isn’t null (not really used much in VBA anyhow), or empty (it’s been
allocated at some point). Currently, I am forcing an error:
On Error Resume Next
Dim dummyString as string
dummyString = sourceDocument.Name
If Err.Number = 462 Then
Set sourceDocument = Nothing
End If
Is there a better way?