BUG: MoveDown Method Behaves Incorrectly When Word Is Hidden (235876)



The information in this article applies to:

  • Microsoft Word 97 for Windows
  • Microsoft Word 2000
  • Microsoft Visual Basic for Applications 5.0
  • Microsoft Visual Basic for Applications 6.0

This article was previously published under Q235876

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 that this is 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:
        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                                                               
    					
  5. To run the macro, press the F5 key.
  6. A MessageBox appears with the text:
    Error #4605 This Command is not available.
  7. 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
				

Modification Type:MajorLast Reviewed:12/12/2003
Keywords:kbAutomation kbbug kberrmsg kbnofix KB235876