-
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'
-
OK thanks,
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
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.
-
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.
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.
-
Thank you so much
I'll try it and ger back to you.
-
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..
-
-
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|