DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 13 of 13
  1. #1
    Join Date
    Mar 2005
    Location
    Beirut, Lebanon
    Posts
    21

    Question VB.NET Question On how to Copy and Paste programmatically

    IF anyone can help me with this I will be very grateful.

    I want to write a program that can copy a selected text in any other active program (like word, excel,...) then paste it in my program to do some editting.

    Is it feasable, can anyone give me a clue how can I do it?
    Last edited by Raffee; 03-31-2005 at 09:57 AM.

  2. #2
    Join Date
    Mar 2005
    Posts
    71
    See more about 'System.Windows.Forms.Clipboard'

  3. #3
    Join Date
    Mar 2005
    Location
    Beirut, Lebanon
    Posts
    21
    OK thanks,
    I'll try it and get back to you.

  4. #4
    Join Date
    Mar 2005
    Location
    Beirut, Lebanon
    Posts
    21
    Thank you again!
    I checked it out, and it works just fine. The problem is I want to copy from other applications, like word or notepad.

    I found no help regarding this subject

  5. #5
    Join Date
    Mar 2005
    Posts
    71
    'System.Windows.Forms.Clipboard' links with the system clipboard. It is cross application.

    Try this code
    Code:
    IDataObject iData = System.Windows.Forms.Clipboard.GetDataObject();
     
    if(iData.GetDataPresent(DataFormats.Text)) 
    {
    	textbox_A.Text = (String)iData.GetData(DataFormats.Text); 
    }
    You will get something if the object in the clipboard is in text format.

  6. #6
    Join Date
    Mar 2005
    Location
    Beirut, Lebanon
    Posts
    21

    Exclamation

    I tried the code you suggested. In this case I have to copy the selected text manually, is there a way to have a function (like a button click) do the copying of the selected text from another open application?

    Like, I open up a word document, highlight some lines, then when I click a button in my vb.net program, the selected text is automatically put on the clipboard so that i can get it into my form?

    I really appreciate your help!
    Last edited by Raffee; 04-06-2005 at 06:42 AM.

  7. #7
    Join Date
    Mar 2005
    Posts
    71
    woo.... it is much more complicate than i thought

    If you target on MS Office applications only, you may try to make an Add-in with remoting. I haven't tried before, but it may works.

  8. #8
    Join Date
    Mar 2005
    Location
    Beirut, Lebanon
    Posts
    21
    Let's say I am aiming at Office applications. How is this done? If you have'nt tried it, at least can you tell me where can I find help?

  9. #9
    Join Date
    Mar 2005
    Posts
    71
    If you are using Visual Studio 2003 or later, there should be a project type called 'Shared Add-in' to create MS Office add-in.

    See
    http://msdn.microsoft.com/library/de...HV01098493.asp
    http://msdn.microsoft.com/library/de...ce06062002.asp

    Remoting is a technique to allow inter-process communication within a workgroup (include local machine). This allows your program to get information from the Office add-in.

    See
    http://msdn.microsoft.com/library/de...wkremoting.asp


    After knowing all the above, the things you need to do is
    1. Creating an Office add-in to get the selected text in the application
    2. Add the necessary remoting module/code to the add-in and your program
    3. Install the Office add-in
    4. Run your program

    I have not tried before, but I hope this can solve your problem.
    Last edited by oupoi; 04-07-2005 at 11:29 PM.

  10. #10
    Join Date
    Mar 2005
    Location
    Beirut, Lebanon
    Posts
    21

    Talking

    Thank you so much
    I'll try it and ger back to you.

  11. #11
    Join Date
    Apr 2009
    Posts
    2

    hi

    Am also doing the same work.. please let me know if there is any way to copy the selected text from a word file(2007) and store it in a string..

  12. #12
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,652
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  13. #13
    Join Date
    Apr 2009
    Posts
    2

    hi

    dude...i have already gone through those links.. Actually i got the solution..

    Code:
     Dim document As Word.Document = Globals.ThisAddIn.Application.ActiveDocument
    
            'Let it speak!
            Dim jai As String = document.ActiveWindow.Selection.Text

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links