Microsoft KB Archive/235876

= BUG: MoveDown Method Behaves Incorrectly When Word Is Hidden =

Article ID: 235876

Article Last Modified on 1/24/2007

-

APPLIES TO


 * Microsoft Word 97 Standard Edition
 * Microsoft Word 2000 Standard Edition
 * 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.



Steps to Reproduce Behavior
 Start Microsoft Word and create a blank document. Press the ALT-F11 keys to enter the Microsoft Visual Basic Editor. Double-click ThisDocument to bring up a code window.  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  To run the macro, press the F5 key. A MessageBox appears with the text:

Error #4605 This Command is not available.

</li> 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.</li></ol>

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

Additional query words: automate automation move down linedown

Keywords: kbautomation kbbug kberrmsg kbnofix KB235876

-

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

© Microsoft Corporation. All rights reserved.