WD97: Automating Word Creates an Additional Document

ID: Q237339


The information in this article applies to:
  • Microsoft Word 97 for Windows


SYMPTOMS

When a Word document object embedded in another file--for example, a Microsoft Excel workbook--is first manipulated via automation and then opened for editing in a separate Word window, an additional "phantom document" appears, called Documentx (where x corresponds to the number Word gives to the next newly created document; for example, Document1 or Document8).

This problem can manifest itself in several ways:

Scenario A

The extra document appears at the first run of the program that automates and then opens the object. The extra document is listed in the document window list in Word. When you try to close the extra document by clicking on the X button in the upper right corner of the document window, the object document is closed instead.

Scenario B

The extra document appears at the first run of the program code that automates and then opens the object. The extra document is not listed in the document window list. When you try to close the extra document by clicking on the X button in the document window's upper right corner, Word hangs and can only be closed using Task Manager.

Scenario C

The extra document does not appear at the first run of the program code that automates and then opens the object. From the second run of the macro on, the extra document appears and is listed in the Window list. When you try to close the extra document by clicking on the X button in the upper right corner of the document window, the object document is closed instead.

Scenario D

The extra document does not appear at the first run of the program code that automates and then opens the object. From the second run of the macro on, the extra document appears and is not listed in the Window list. When you try to close the extra document, Word crashes with a Page Fault.


CAUSE

This happens only under the following circumstances:

The embedded document object is manipulated via automation. After automation, the document is opened via program code, not manually.


RESOLUTION

A supported fix that corrects this problem is now available from Microsoft, but it has not been fully regression tested and should be applied only to systems experiencing this specific problem.

To resolve this problem, contact Microsoft Product Support Services to obtain the fix. For a complete list of Microsoft Product Support Services phone numbers and information on support costs, please go to the following address on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp

The English version of this fix should have the following file attributes or later:


   Date      Time       Size      File name     Platform
   -------------------------------------------------------------
   01.04.99  02:58   5.326.608   WinWord.exe     x86
   01.04.99  02:58   1.158.416   Wwintl32.dll    x86
 


STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article.
This problem does not occur with Microsoft Word 2000.


MORE INFORMATION

Steps to Reproduce Problem

Steps to Reproduce Scenarios A-C with automation from Excel 97 to Word 97:

  1. In a new Excel workbook, insert a Word document object on Sheet1. To do this, click in Object in the Insert menu, select "Microsoft Word Document" in the Object Type list box, and click on OK.


  2. Switch back to the worksheet.


  3. Press CTRL+F11 to start the Visual Basic Editor.


  4. Click on Module in the Insert menu to insert a new module. Type the macros below in a new module in this workbook.


  5. Run one of the three automation macros.


  6. Run the macro OpenWord1.


  7. Look at the document windows that appear in Word, and click on the Window menu to check what document names are displayed in the Window list.


  8. For reproducing scenario C, close Word and run the macro OpenWord1 again.


Macros:



Sub Automation1()
'usually leads to scenario A
With Worksheets("Sheet1").OLEObjects(1)
   .Activate
    Set bla = .Object.Application
    bla.Selection.TypeText "test"
    bla.Quit
    Set bla = Nothing
End With
Worksheets("Sheet1").Range("C10").Select
End Sub 

Sub Automation2()
'usually leads to scenario B
With Worksheets("Sheet1").OLEObjects(1)
    .Activate
    .Object.Application.Selection.TypeText "test"
    .Object.Application.Quit
End With
Worksheets("Sheet1").Range("C10").Select
End Sub 

Sub Automation3()
'usually leads to scenario C
With Worksheets("Sheet1").OLEObjects(1)
    .Activate
    .Object.Application.Selection.TypeText "test"
End With
Worksheets("Sheet1").Range("C10").Select
End Sub 

Sub OpenWord1()
'opens Word document object in a separate Word instance
  Worksheets("Sheet1").OleObjects(1).Verb "2"
End Sub 
Steps to Reproduce Scenario C or D with automation from PowerPoint 97 to Word 97:
  1. Start PowerPoint 97.


  2. Press CTRL+F11 to start the Visual Basic Editor.


  3. Click on Module in the Insert menu to insert a new module into the presentation. Type the macros below in the new module.
    
    Sub BuildSlide() 
       ActiveWindow.View.GotoSlide Index:=ActivePresentation.Slides.Add(Index:=2, _
          Layout:=ppLayoutText).SlideIndex 
       ActiveWindow.Selection.SlideRange.Shapes.SelectAll 
       ActiveWindow.Selection.ShapeRange.Delete 
       ActiveWindow.Selection.SlideRange.Shapes.AddOLEObject(Left:=120, _
          Top:=110, Width:=480, Height:=320, ClassName:="Word.Document.8", _
          Link:=msoFalse).Select 
       ActiveWindow.Selection.ShapeRange.OLEFormat.Activate 
       ActiveWindow.Selection.SlideRange.Shapes.AddShape(msoShapeOval, _
          132#, 24#, 324#, 36#).Select 
       ActiveWindow.Selection.SlideRange.Shapes.SelectAll 
       ActiveWindow.Selection.ShapeRange.Group.Select 
    End Sub  
    
    Sub OpenWordDoc() 
       Dim shpMember As Shape 
       For Each shpMember In 
          ActiveWindow.Selection.SlideRange.Shapes(1).GroupItems 
          If shpMember.Type = msoEmbeddedOLEObject Then 
             If shpMember.OLEFormat.Object.Application.Name = _
                "Microsoft Word" Then 
                shpMember.OLEFormat.DoVerb 2 
             End If 
          End If 
       Next 
    End Sub  


  4. Run the macro BuildSlide.


  5. Run the macro OpenWordDoc.


  6. Close the object document.


  7. Repeat steps 5 and 6.


Additional query words:

Keywords : kbdta
Version : WINDOWS:97
Platform : WINDOWS
Issue type : kbbug


Last Reviewed: August 27, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.