BUG: MoveDown Method Behaves Incorrectly When Word is Hidden

ID: Q235876


The information in this article applies to:
  • Microsoft Word 97 for Windows
  • Microsoft Word 2000
  • Microsoft Visual Basic for Applications versions 5.0, 6.0


SYMPTOMS

When Microsoft Word is not visible, using the MoveDown method of the Selection object does not behave as expected. This behavior might occur when MoveDown is called either from a Word macro or from another program that is automating Word.


RESOLUTION

There are two possible workarounds:

  • Because the incorrect behavior occurs when Word is not visible, you can make Word visible when using the MoveDown method by setting the Application.Visible property equal to True.


  • Instead of extending the current selection using the MoveDown method, explicitly select the range you want to manipulate.



STATUS

Microsoft has confirmed this to be a problem in Microsoft Word 97 and 2000.


MORE INFORMATION

Steps to Reproduce Behavior

  1. Start Microsoft Word and create a blank document.


  2. Press the ALT-F11 keys to enter the Microsoft Visual Basic Editor.


  3. Double-click ThisDocument to bring up a code window.


  4. Copy the following code into the code window:


  5. 
        Sub Macro1()  
                                                                                                                                                                                       
           Dim doc As Document
        
           Application.Visible = False
        
           Set doc = ActiveDocument
        
           'Add a new table
           doc.Tables.Add Range:=Selection.Range, NumRows:=37, _
                       NumColumns:=16
                       
           'Merge the cells in column 1 of rows 1-3
           Selection.MoveDown wdLine, 2, wdExtend
           On Error Resume Next
           Selection.Cells.Merge
           If Err <> 0 Then
               MsgBox "Error #" & Err.Number & vbNewLine _
                    & Err.Description
           End If
        
           Application.Visible = True
        End Sub                                                                
  6. To run the macro, press the F5 key.


  7. A MessageBox appears with the text:


  8. Error #4605 This Command is not available.
  9. Go back to the Word window and note that the document now contains a table. Observe that the whole table is currently selected rather than just the first three cells of column 1 as you would expect.


Workaround

To work around the problem, you can modify the code to explicitly select the range rather than using the MoveDown method. Change the following line of code in the above sample:

Selection.MoveDown wdLine, 2, wdExtend 
to:

doc.Range(Start:=doc.Tables(1).Cell(1, 1).Range.Start, _
                End:=doc.Tables(1).Cell(3, 1).Range.End).Select 

© Microsoft Corporation 1999, All Rights Reserved.
Contributions by Ben Burgess, Microsoft Corporation

Additional query words: automate automation move down linedown

Keywords : kberrmsg kbAutomation KbVBA kbGrpDSO kbWord97 kbword2000
Version : WINDOWS:2000,5.0,6.0,97
Platform : WINDOWS
Issue type : kbbug


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