Microsoft KB Archive/220420

= WD2000: VBA: Text Placed in Wrong Document Using Hidden Documents =

Article ID: 220420

Article Last Modified on 6/17/2005

-

APPLIES TO


 * Microsoft Word 2000 Standard Edition

-



This article was previously published under Q220420



SYMPTOMS
When you try to add text to a document that was hidden using the Visible statement, you may receive unexpected results.

For example, the following procedure demonstrates this behavior.

In the following procedure, if you have a document open (MyDoc.doc) before running the procedure, when you run the procedure, a new document is created. Instead of the the text being inserted into the new document as expected, the text is inserted into MyDoc.doc: Sub HideDoc Dim lngDoc As Long Dim sDocName As String Documents.Add sName = ActiveDocument.Name lngDoc = ActiveWindow.WindowNumber ActiveWindow.Visible = False Windows(lngDoc).Activate Selection.TypeText sName ActiveWindow.Visible = True End Sub



RESOLUTION
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 resolve this problem, you can assign a variable to the Visual Basic for Applications Document object to access and manipulate the hidden document window.

For example: Sub HiddenDoc Dim oDoc as Document Dim sDocName As String Set oDoc = Documents.Add sDocName = oDoc.Name With oDoc.ActiveWindow .Visible = False .Selection.TypeText sDocName .Visible = True End With End Sub



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

Additional query words: vba

Keywords: kbbug kbnofix KB220420

-

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

© Microsoft Corporation. All rights reserved.