Prev: Using Building Blocks, Content Controls and XMLMappings to generate multi-page template-generated sections in a Word Document
Next: Which field did I exit...
From: George Lee on 11 Mar 2010 10:28 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? |