|
-
Oct 17th, 2007, 05:31 AM
#1
[2.0] Select All in Winword
Hi all,
I am using this code, to open a word document using Latebinding.Can any one help to copy the contents of the opened document to clipboard.
Code:
private void button2_Click(object sender, EventArgs e)
{
object WordApp;
object WordDoc;
object Doc;
ArrayList nFile=new ArrayList();
Object[] objFalse = new Object[1];
objFalse[0] = true;
object[] nfilename=new object[1];
nfilename[0]= @"c:\abe.DOC";
Type objClassType = Type.GetTypeFromProgID("Word.Application");
WordApp = Activator.CreateInstance(objClassType);
objClassType.InvokeMember("Visible", System.Reflection.BindingFlags.SetProperty, null, WordApp, objFalse);
WordDoc = WordApp.GetType().InvokeMember("Documents",System.Reflection.BindingFlags.GetProperty, null, WordApp, null);
Doc = WordDoc.GetType().InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, WordDoc, nfilename);
Object WordView = WordApp.GetType().InvokeMember("View", System.Reflection.BindingFlags.InvokeMethod, null, WordDoc, null);
}
Thanks in Advance
Dana
Last edited by danasegarane; Oct 17th, 2007 at 06:49 AM.
Please mark you thread resolved using the Thread Tools as shown
-
Oct 17th, 2007, 09:11 AM
#2
Re: [2.0] Select All in Winword
Whenever I try to automate something in Word, I found the thing that can really help is to record a macro of it and then see what code gets produced. From doing that I was able to create this code to copy the data:
Code:
object WordSelection;
WordSelection = WordApp.GetType().InvokeMember("Selection", System.Reflection.BindingFlags.GetProperty, null, WordApp, null);
WordSelection.GetType().InvokeMember("WholeStory", System.Reflection.BindingFlags.InvokeMethod, null, WordSelection, null);
WordSelection.GetType().InvokeMember("Copy", System.Reflection.BindingFlags.InvokeMethod, null, WordSelection, null);
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
|
Click Here to Expand Forum to Full Width
|