7 Replies - 830 Views - Last Post: 12 May 2013 - 01:27 AM Rate Topic: -----

#1 bowlertreborn6j8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 11-May 13

how can i access msword paragraph options in automated mode

Posted 11 May 2013 - 08:06 AM

I am actually programming in Delphi 7 and want to automate output to ms word how can I access the paragraph formatting to center text on the page if have tried the following code but get error saying paragraph not available

wordapplication.selection.paragraph.alignment:='center';

hope someone can help
Is This A Good Question/Topic? 0
  • +

Replies To: how can i access msword paragraph options in automated mode

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3224
  • View blog
  • Posts: 10,825
  • Joined: 12-December 12

Re: how can i access msword paragraph options in automated mode

Posted 11 May 2013 - 08:16 AM

It would be .Paragraphs(1) if you intended the first paragraph, but the alignment should be set to

wdAlignParagraphCenter    'a word intrinsic constant

which has the numerical value of 1.

This post has been edited by andrewsw: 11 May 2013 - 08:17 AM

Was This Post Helpful? 1
  • +
  • -

#3 bowlertreborn6j8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 11-May 13

Re: how can i access msword paragraph options in automated mode

Posted 11 May 2013 - 12:09 PM

This code generates the following error
Method paragraphs not supported by automation object
it is not a question of generating paragraphs but of aligning text on the page

below is the code I am using everything else works perfectly except for the alignment
procedure TForm1.Button1Click(Sender: TObject);
 var
    WordApplication, WordDocument: Variant;
 begin
    WordApplication := CreateOleObject('Word.Application') ;
    WordDocument := WordApplication.Documents.Add;
    wordapplication.selection.font.size:=18;
    wordapplication.selection.paragraph.alignment(1);
    WordApplication.Selection.TypeText('Hello world') ;
    Worddocument.SaveAs(FileName := 'C:\bowls\rr\hello.Doc',
                        AddToRecentFiles := False) ;
    WordApplication.Quit(False)
 end;


*** EDIT ***
Please use code tags when posting code!
:code:

This post has been edited by GunnerInc: 11 May 2013 - 06:21 PM
Reason for edit:: Added code tags

Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3224
  • View blog
  • Posts: 10,825
  • Joined: 12-December 12

Re: how can i access msword paragraph options in automated mode

Posted 11 May 2013 - 12:20 PM

That code, which is not wrapped in code-tags, doesn't use the paragraphs() that I suggested.

Highlight your code and click the CODE button that appears above the text area.

You should also provide more precise error information, including an indication of the line(s) they refer to.

This is definitely wrong:

wordapplication.selection.paragraph.alignment(1);

I suppose I need to be more exact :whistling::

wordapplication.selection.paragraphs(1).alignment = 1;

or, maybe for delphi:

wordapplication.selection.paragraphs(1).alignment := 1;

This post has been edited by andrewsw: 11 May 2013 - 12:22 PM

Was This Post Helpful? 0
  • +
  • -

#5 bowlertreborn6j8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 11-May 13

Re: how can i access msword paragraph options in automated mode

Posted 11 May 2013 - 12:50 PM

this last code did not solve problem
Exception Raised is Class EOLe Exception with Message Method Paragraphs not supported by Automation Object
at line Marked { ***}

below is entire unit code

unit printtowordunit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
uses
    ComObj;


procedure TForm1.Button1Click(Sender: TObject);
 var
    WordApplication, WordDocument: Variant;
 begin
    WordApplication := CreateOleObject('Word.Application') ;
    WordDocument := WordApplication.Documents.Add;
    wordapplication.selection.font.size:=18;
    wordapplication.selection.paragraphs(1).alignment := 1; {*** Error Here ***}
    WordApplication.Selection.TypeText('Hello world') ;
    Worddocument.SaveAs(FileName := 'C:\bowls\rr\hello.Doc',
                        AddToRecentFiles := False) ;
    WordApplication.Quit(False)
 end;


end.


*** EDIT ***
Please use code tags when posting code!
:code:

This post has been edited by GunnerInc: 11 May 2013 - 06:22 PM
Reason for edit:: Added those elusive code tags

Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3224
  • View blog
  • Posts: 10,825
  • Joined: 12-December 12

Re: how can i access msword paragraph options in automated mode

Posted 11 May 2013 - 01:19 PM

Maybe Delphi (somehow..) switches the indexing so that it starts from 0. It shouldn't do this, but try Paragraphs(0) just for the thrill.

Try switching this line around:

WordApplication.Selection.TypeText('Hello world') ;

to see if it is a problem specifically with Paragraphs.

Similar code works from Word VBA and you have exhausted any knowledge I have of Delphi.

BTW It is disappointing that you still haven't attempted to enclose your code in code-tags. It isn't difficult and it tells you how to do this directly in the area where you are typing.

Good luck! I've no idea if anyone else here uses Delphi.

This post has been edited by andrewsw: 11 May 2013 - 01:20 PM

Was This Post Helpful? 0
  • +
  • -

#7 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3224
  • View blog
  • Posts: 10,825
  • Joined: 12-December 12

Re: how can i access msword paragraph options in automated mode

Posted 11 May 2013 - 01:34 PM

One last stab would be:

WordApplication.Selection.Paragraphs.Item(1).Alignment := 1;

because Item is a default Word property, which perhaps it doesn't default to from Delphi. Yeah, bet this works ;)

This post has been edited by andrewsw: 11 May 2013 - 01:35 PM

Was This Post Helpful? 1
  • +
  • -

#8 bowlertreborn6j8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 11-May 13

Re: how can i access msword paragraph options in automated mode

Posted 12 May 2013 - 01:27 AM

Thank you for your help the last line of code you sent works perfectly
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1