Board index » delphi » How do you return a Selection object from WORD 97 using Delphi 3?

How do you return a Selection object from WORD 97 using Delphi 3?

Can someone please help me......
I am trying to extend a table by adding a new row in a Word document
after moving out of the table when using Cell.Next  To catch the fact
that I have moved out of the table I use try .. except.  According to
the VB Help in WORD 97 using the Select property of an object passes a
Selection object which allows the Extend function to be used, in Delphi
the Select function is defined as a procedure that does not pass
anything back !
If anyone has any ideas or code I would be very grateful.
Cheers,
{*word*106}ie.
PS I import the Word8.olb and use early binding.
--
Richard Ward

 

Re:How do you return a Selection object from WORD 97 using Delphi 3?


Hi Richard,

I use the nextcell call all the time and in always extends the table for
you
automaticlly I have included a piece of code that produces one of my
reports
that uses a table in the word document.
I have been using "word.basic" but "word.application" seems to work the
same.

you might want to take a look at a package I have purchased from
http://www.edit.de/oleander/home.htm if nothing else you can learn from
there
code.

Var
  MSWord : Variant;

Procedure LoadWord;
Procedure UnLoadWord;

implementation

Var
    WordLoaded : Boolean;

Procedure LoadWord;
Begin
  If NOT WordLoaded Then
    MSWord := CreateOLEOBJECT('word.basic');
  WordLoaded := True;
End;

Procedure UnLoadWord;
Begin
  If WordLoaded Then
    Begin
      try
        WordLoaded := False;
        MSWord.fileexit;
      except on EOleError do
      end
    End;
End;

Procedure MsWorkSheet( SL : TStringList );
Var
  T  : Integer;
  S : String;
  FileName  : String;
  TempFname : String;

begin

    TempFName := 'd:\temp.doc';
    If FileExists(TempFname) Then
       DeleteFile(TempFname);

    FileName  := Settings.WorkSheet;

      MSWord.FileNew( Template := FileName);
{Save Document as Word 6.0 format }
      MSWord.FileSaveAs( Name := TempFName, format :=
                                            MSWord.ConverterLookup('Word
6.0/95') );

        If (Settings.TopMargin  <> '') And
          (Settings.BottomMargin  <> '') And
          (Settings.LeftMargin  <> '') And
          (Settings.RightMargin  <> '') And
          (Settings.Gutter <> '') And
          (Settings.HeaderDistance  <> '') And
          (Settings.FooterDistance <> '' ) Then
       MsWord.FilePageSetup( TopMargin := Settings.TopMargin,
                             BottomMargin := Settings.BottomMargin,
                             LeftMargin := Settings.LeftMargin,
                             RightMargin := Settings.RightMargin,
                             Gutter := Settings.Gutter,
                             HeaderDistance := Settings.HeaderDistance,
                             FooterDistance := Settings.FooterDistance,
                             ApplyPropsTo := 4 );

  MSWord.EditGoto( Destination := 'WSDATE');
  S := FormatDateTime('dd-mm-yyyy',now);
  MSWord.Insert(S);

  MSWord.EditGoto( Destination := 'DETAILS');       { Bookmark for

First Field in Table }
  T := 0;
  While T <= SL.Count -2 do
    Begin
      S := SL.Strings[t];
      MSWord.Insert(S);
      MSWord.NextCell;
      Inc(t);
      S := SL.Strings[t];
      MSWord.Insert(S);
      MSWord.NextCell;
      Inc(t);
      S := SL.Strings[t];
      MSWord.Insert(S);
      MSWord.NextCell;
      MSWord.NextCell;
      MSWord.NextCell;
      Inc(t);
     End;

  MSWord.EditGoto( Destination := 'TOTAL');
  S := SL.Strings[SL.Count -1];
  MSWord.Insert(S);

  MSWord.FilePrint(NumCopies := 1);
{Save Document as Word 6.0 format }
      MSWord.FileSaveAs( Name := TempFName, format :=
                                            MSWord.ConverterLookup('Word
6.0/95') );
  MSWord.FileClose(1);
end;

Quote
Richard Ward wrote:
> Can someone please help me......
> I am trying to extend a table by adding a new row in a Word document
> after moving out of the table when using Cell.Next  To catch the fact
> that I have moved out of the table I use try .. except.  According to
> the VB Help in WORD 97 using the Select property of an object passes a
> Selection object which allows the Extend function to be used, in Delphi
> the Select function is defined as a procedure that does not pass
> anything back !
> If anyone has any ideas or code I would be very grateful.
> Cheers,
>{*word*106}ie.
> PS I import the Word8.olb and use early binding.
> --
> Richard Ward

Other Threads