Hi,
I am trying to move some text within the document, but without using cut/paste. In Word it is possible to move text by selecting it and dragging it with the mouse. The same thing is achievable using the keyboard by pressing F8 to select some text and then pressing F2 to select the place to move the text to.
Under the covers Word enters what is called "special mode", and the boolean property Application.SpecialMode can be queried to find out if Word is currently in it. Unfortunately this is a get only property, so it is not possible to make Word go into special mode by setting it to true.
I recorded the following macro that does exactly what I want to do through VSTO, but I am unable to find the appropriate methods/properties for achieving this.
' F8 was pressed
Selection.Extend
' The right arrow key was pressed to select some text
Selection.MoveRight Unit:=wdCharacter, Count:=10
' F2 was pressed, after this Word is in special mode
WordBasic.MoveText
' The down arrow key was pressed to move to the point where the text should be moved
Selection.MoveDown Unit:=wdLine, Count:=2
' The left arrow key was pressed to move to the point where the text should be moved
Selection.MoveLeft Unit:=wdCharacter, Count:=9
' The Enter key was pressed to move the text to the current cursor position.
' After this line Word is no longer in special mode
WordBasic.OK
Any help or suggestions would be greatly appreciated.
Thank you
Angelos Petropoulos

Moving text within a document without using the clipboard
jog
Hi Kathleen,
Thank you for your suggestion. That is a good way for avoiding using the clipboard, but because it involves a copy-paste-delete, the elements of the document that cannot exist twice are affected. For example, if the original selection contains a bookmark, during the copy and paste the bookmark is not copied along and is completely removed from the document when the original selection is deleted.
I did a little bit more research and with the help of MSDN and the Visual Basic Equivalents [Word 2003 VBA Language Reference] page I have discovered that there is a property Application.WordBasic exposed in VSTO, but since it's return value is of type Object I am unsure as to how to use it. Any ideas
Thank you
Angelos Petropoulos
ejgarci
Hi Aggelos,
The functionality you described (Pressing F2 to enter Externd mode, F8 to indicate selection has been made, and Enter to move the text) still works on a VSTO Word document. Perhaps if you could explain how you intend to modify that functionality (the reason you need to write code), we can help. Also, if there is a specific reason why you don't want to use Clipboard, you could always assign the text in the selection to a variable, and then assign the variable to a new selection.
Kathleen McGrath
develop
Hi Martin,
As my original post explains, I know how to implement this functionality in VBA. What I am after is the API exposed in VSTO to perform the same functionality.
chaospilot
Well, both Selection and WordBasic are properties of the Application object, so to use that code from VSTO, you'd specify something like (assuming VB is the language you're using, and Me refers to the document):
Me.Application.Selection.XXX
where XXX is the method you're trying to call (like Extend or MoveRight). However, the WordBasic object is quite tricky to use from VSTO. I would recommend using Selection.Cut instead of WordBasic.MoveText and Selection.Paste instead of WordBasic.OK.
Other than that, though, there are no real differences between VBA and VSTO in this case - you just need to specify the "Me.Application" in VSTO, but the object model is essentially the same and can be used in the same way in either environment.
Cheers,
Michael Whalen [MSFT]
AnthonyKautz
Hi Angelos,
Unfortunately, I don't know the equivalent VB code for the WordBasic commands you listed.
If you want to be able to include elements other than text, such as tables, graphics, etc. you might try creating an autotext entry for the selection. Then you could insert the autotext entry at the new location and delete the original selection.
I hope this helps,
Kathleen McGrath
StimpE
This question would be best asked on the Word specific programning newsgroup: http://msdn.microsoft.com/newsgroups/default.aspx dg=microsoft.public.word.vba.general&lang=en&cr=US
since, this forum is for VSTO-specific questions only.
Hope this helps
princess275
I apologize - I completely missed the "without using the clipboard" part of your question, so my answer won't work.
Maybe you could use the Move method of a Range to move the text Select the text and get the range using Selection.Range. Then, use one of the Move related methods of the Range object - the simple "Move" method is documented here: http://msdn.microsoft.com/library/default.asp url=/library/en-us/vbapb11/html/pbmthMove_HV03084865.asp - but there are other similar methods you can use like MoveDown, MoveLeft, etc. that may be of use.
Cheers,
Michael Whalen [MSFT]
UGimelS
Hi Kathleen,
I want to move a piece of the document from one place to another without using the clipboard and I want to do this programatically. Picture the following scenario
1. User selects some text in the document
2. Users click on the "Move to next page" button in the Actions Pane
3. Using VSTO code the selected text is moved to the next page
The reason I do not want to use the clipboard is because if I do, anything that is already there will be overwritten. I haven't tried your suggest out yet, but as far as I recall putting the text of the current selection in a variable of type String will not work with objects and tables.
All I am after is doing in VSTO what the VBA code snippet that is in my original message does, specifically I need the equivalent of WordBasic.MoveText and WordBasic.OK in VSTO
Thank you for looking into this
Angelos Petropoulos