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.
See more about 'System.Windows.Forms.Clipboard'
I'll try it and get back to you.
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
'System.Windows.Forms.Clipboard' links with the system clipboard. It is cross application.
Try this code
You will get something if the object in the clipboard is in text format.
IDataObject iData = System.Windows.Forms.Clipboard.GetDataObject();
textbox_A.Text = (String)iData.GetData(DataFormats.Text);
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.
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.
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?
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.
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.
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.
Thank you so much
I'll try it and ger back to you.
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..
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
dude...i have already gone through those links.. Actually i got the solution..
Dim document As Word.Document = Globals.ThisAddIn.Application.ActiveDocument
'Let it speak!
Dim jai As String = document.ActiveWindow.Selection.Text
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center