Microsoft KB Archive/220504

= WD2000: Documents/Windows Collection Fails to Include Hidden Documents =

Article ID: 220504

Article Last Modified on 6/17/2005

-

APPLIES TO


 * Microsoft Word 2000 Standard Edition

-



This article was previously published under Q220504



SYMPTOMS
When you use the Visible property of the Open method for the Documents collection to open an existing document as hidden, the document count and the window count are not incremented.

For example, the following Visual Basic for Applications procedure demonstrates this problem: Sub CountHiddenDocs Documents.Close ' Close ALL open documents. Documents.Add  ' Add a new blank document. With Application.Documents ' Open MyDoc.Doc document as hidden. .Open "\MyDoc.Doc", Visible:=False ' Return the number of documents in the Documents collection. MsgBox "There are" & .Count & " documents open in Word." MsgBox MsgBox "There are " & Windows.Count & _ " window(s) in the Windows collection." End With End Sub Running the procedure results in the message box displaying 1 instead of 2 for both the Documents and Windows collection.

Furthermore, you cannot make visible a document you open as hidden using the ActiveWindow.Visible command. Attempting to do so may result in the following error message:

Run-time error '91': Object variable or With block variable not set.

-or-

Run-time error '4248': This command is not available because no documents are opened.

For example, the following Visual Basic for Applications procedure demonstrates the run-time error '91': Sub CountHiddenDocs Dim Doc As Document Dim Doc1 As Document Documents.Close ' Close ALL open documents. Documents.Add  ' Add a new blank document. With Application.Documents ' Open MyDoc.Doc document as hidden. Set Doc1 = .Open("\MyDoc.Doc", Visible:=False) ' Return the number of documents in the Documents collection. MsgBox "There are" & .Count & " documents open in Word." End With

' Using the Documents collection fails to unhide ' hidden documents but does not return an error. For Each Doc In Documents Doc.ActiveWindow.Visible = True Next ' Using the document object variable fails to unhide the ' hidden document and returns the error mentioned earlier ' in this article. Doc1.ActiveWindow.Visible = True End Sub



RESOLUTION
To resolve this problem, obtain Microsoft Office 2000 Service Release 1/1a (SR-1/SR-1a).

To obtain SR-1/SR-1a, click the article number below to view the article in the Microsoft Knowledge Base:

245025 OFF2000: How to Obtain and Install Microsoft Office 2000 Service Release 1/1a (SR-1/SR-1a)

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. To temporarily work around this problem, you can treat the hidden document, for opening and referencing, as a separate document object. The following Visual Basic for applications procedure demonstrates this work around:

Sub CountHiddenDocs ' This macro opens an existing document as hidden ' then makes the hidden document visible. Dim Doc1 As Document

' Open MyDoc.Doc document as hidden. Set Doc1 = Documents.Open("\MyDoc.Doc", Visible:=False)

' Reset the document object variable to make visible the ' hidden document. '  ' NOTE: The following command line will NOT open a   ' second instance of the hidden document but instead ' make the currently open, hidden instance of the ' document visible. Set Doc1 = Documents.Open("\MyDoc.Doc", Visible:=True) Doc1.ActiveWindow.Activate End Sub



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. This problem was corrected in Microsoft Office 2000 SR-1/SR-1a.



MORE INFORMATION
For more information about the Documents collection, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type Documents collection in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

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

Additional query words: vba invisible

Keywords: kbbug kbnofix KB220504

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.