Open Word document error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alan T

    Open Word document error

    In my C# application, I want to open a Word document using the code from the
    Help:
    using Microsoft.Offic e.Interop.Word;

    object readOnly = true;
    object fileName = @"C:\Test\NewDo cument.doc";

    this.Applicatio n.Documents.Ope n(ref fileName,
    ref missing, ref readOnly, ref missing, ref missing, ref missing,
    ref missing, ref missing, ref missing, ref missing, ref missing,
    ref missing, ref missing, ref missing, ref missing, ref missing);I got a
    compilation error:'WindowsA pplication2.For m1' does not contain a definition
    for 'Application'




  • Ciaran O''Donnell

    #2
    RE: Open Word document error

    You need to declare an instance of Word:

    Microsoft.Offic e.Interop.Word. Application app = new
    Microsoft.Offic e.Interop.Word. ApplicationClas s();
    object readOnly = true;
    object fileName = @"C:\Test\NewDo cument.doc";
    app.Documents.O pen(ref fileName,
    ref missing, ref readOnly, ref missing, ref missing, ref missing,
    ref missing, ref missing, ref missing, ref missing, ref missing,
    ref missing, ref missing, ref missing, ref missing, ref missing);

    HTH

    Ciaran O'Donnell

    "Alan T" wrote:
    In my C# application, I want to open a Word document using the code from the
    Help:
    using Microsoft.Offic e.Interop.Word;
    >
    object readOnly = true;
    object fileName = @"C:\Test\NewDo cument.doc";
    >
    this.Applicatio n.Documents.Ope n(ref fileName,
    ref missing, ref readOnly, ref missing, ref missing, ref missing,
    ref missing, ref missing, ref missing, ref missing, ref missing,
    ref missing, ref missing, ref missing, ref missing, ref missing);I got a
    compilation error:'WindowsA pplication2.For m1' does not contain a definition
    for 'Application'
    >
    >
    >
    >
    >

    Comment

    • Alan T

      #3
      Re: Open Word document error

      Hi,

      What should I add to my Reference ?

      "Ciaran O''Donnell" <CiaranODonnell @discussions.mi crosoft.comwrot e in
      message news:4A694466-B260-4B12-BEF7-2FCD316ECF24@mi crosoft.com...
      You need to declare an instance of Word:
      >
      Microsoft.Offic e.Interop.Word. Application app = new
      Microsoft.Offic e.Interop.Word. ApplicationClas s();
      object readOnly = true;
      object fileName = @"C:\Test\NewDo cument.doc";
      app.Documents.O pen(ref fileName,
      ref missing, ref readOnly, ref missing, ref missing, ref missing,
      ref missing, ref missing, ref missing, ref missing, ref missing,
      ref missing, ref missing, ref missing, ref missing, ref missing);
      >
      HTH
      >
      Ciaran O'Donnell
      >
      "Alan T" wrote:
      >
      >In my C# application, I want to open a Word document using the code from
      >the
      >Help:
      >using Microsoft.Offic e.Interop.Word;
      >>
      >object readOnly = true;
      >object fileName = @"C:\Test\NewDo cument.doc";
      >>
      >this.Applicati on.Documents.Op en(ref fileName,
      > ref missing, ref readOnly, ref missing, ref missing, ref missing,
      > ref missing, ref missing, ref missing, ref missing, ref missing,
      > ref missing, ref missing, ref missing, ref missing, ref missing);I
      >got a
      >compilation error:'WindowsA pplication2.For m1' does not contain a
      >definition
      >for 'Application'
      >>
      >>
      >>
      >>
      >>

      Comment

      Working...