We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Microsoft 'Selection' alternative

I am working on a project where i am using Microsoft ‘Selection.paste’ and ‘Selection.TypeText’.
How can i replicate this in Aspose?


Thanks for your inquiry. Please note that Aspose.Words’ model is quite different from the Microsoft Word’s Object Model in that it represents the document as a tree of objects more like an XML DOM tree. If you worked with any XML DOM library you will find it is easy to understand and work with Aspose.Words. When you load a Word document into Aspose.Words, it builds its DOM and all document elements and formatting are simply loaded into memory. Please read the following article for more information on DOM:
Aspose.Words Document Object Model

You can clone the desired content (nodes) and insert them into any location in the document. Please ZIP and attach your input and expected output documents here for our reference. We will then provide you code example according to your requirement.

Hi Tahir,

Thanks for your reply. I’ll provide my sample code. I’d like to replace content from Clipboard. Please kindly help me to achieve this.

    Dim oBookmarks As Aspose.Words.BookmarkCollection = Nothing
    Dim oBookmark As Aspose.Words.Bookmark = Nothing
    'Dim oSelection As Word.Selection = Nothing

        oBookmarks = wordDocument.Range.Bookmarks
        For Each oBookmark In oBookmarks
            If oBookmark.Name = bookmarkName Then
                If useClipboard Then
                    'wordApplication.Selection.Paste() 'Microsoft Interop property. Need to achieve this
                    wordDocument.Range.Bookmarks(oBookmark.Name).Text = bookmarkValue
                End If

                Exit For
            End If


Thanks for your inquiry. Aspose.Words does not provide API to get text from clipboard. However, you can use Clipboard.GetText method to get the text from clipboard and set bookmark’s text as you are doing in your code.