Article ID: 209160
Article Last Modified on 6/17/2005
APPLIES TO
- Microsoft Word 2000 Standard Edition
This article was previously published under Q209160
SYMPTOMS
If you attempt to use Visual Basic for Applications to change the properties of a document, you may receive one of the following error messages:
-or-
-or-
CAUSE
One of these error messages may appear when no documents are currently open or the document you are referencing is not open.
Word can only change the properties of an open (or visible) document.
NOTE: These error messages may also appear if you have opened the document with the Visible property set to False. For additional information about treating hidden documents in the document collection, please see the following article in the Microsoft Knowledge Base:
220504 WD2000: Documents/Windows Collection Fails to Include Hidden Documents
NOTE: In earlier versions of Word, no error message is displayed, and no document properties are changed.
WORKAROUND
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. The following sample Visual Basic for Applications macros demonstrate how to change the value of the Title field in the Properties dialog box.
This following sample includes code to trap the error, in case there are no documents open, and display a message:
Sub ChangeDocProperties() On Error GoTo ErrHandler ActiveDocument.BuiltInDocumentProperties("Title") = "My Title" Exit Sub ErrHandler: If Err <> 0 Then ' Display an error message. MsgBox Err.Description 'Clear the error. Err.Clear Resume Next End If End Sub
The following sample includes code to
- Trap the error, in case there are no documents open.
- Within the error trap, create a new document.
- Resume execution at the line that caused the error.
Sub ChangeDocProperties() On Error GoTo ErrHandler ActiveDocument.BuiltInDocumentProperties("Title") = "My Title" Exit Sub ErrHandler: If Err <> 0 Then 'Add a document. Documents.Add 'Clear the error. Err.Clear 'Execute the code that caused the error. Resume End If End Sub
MORE INFORMATION
For more information about how to use the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:
212536 OFF2000: How to Run Sample Code from Knowledge Base Articles
REFERENCES
For more information about getting help with Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base:
226118 OFF2000: Programming Resources for Visual Basic for Applications
Additional query words: vb vba vbe
Keywords: kbmacroexample kbprogramming kbprb kbpending kbcode KB209160