Results 1 to 2 of 2

Thread: [2.0] Select All in Winword

  1. #1

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    [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

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    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
  •  



Click Here to Expand Forum to Full Width