Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting text alignment in Word from another application

Status
Not open for further replies.

pmonett

Programmer
Sep 5, 2002
2,632
FR
Greetings,

I am trying to collate information in a Lotus Notes database and present a report in a Word document. I can create the Word document and fill in the text I need without any problem. I even know how to set bold or italic/underlined font where needed.
The last thing I am trying is to get the text centered. This simply does not work.
I have tried with all the following code examples :

1) worddoc.activewindow.selection.paragraphs.format.alignment = 1
2) worddoc.activewindow.selection.paragraphformat.alignment = 1
3) worddoc.paragraphs.alignment = 1
4) worddoc.activewindow.selection.find.paragraphformat.alignment = 1

These lines are taken directly from the online MSDN library. They do not work for me. My values are correct because I know that left/center/right/full is 0/1/2/3.

What is not working ? What magic combination should I use ?

Thanks in advance for any help.

Pascal.
 
Good idea. Unfortunately, the macro returns

Selection.ParagraphFormat.Alignment

which in turns creates an error when I try

worddoc.Selection.ParagraphFormat.Alignment

and if I indicate worddoc.activewindow in front then I'm back to code example #2.
 
What is in WordDoc? I can not be Application.Document for Selection. Use Application with Selection.

wrdAPP.Selection.ParagraphFormat.Alignment = 1 'wdAlignParagraphCenter Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
I am writing this code in Lotus Notes. For me, I have to declare an application (Word), then I can use the methods and properties associated with the application (like everybody else I guess).

Therefor, my declarations are as follows :

First, declare and create a Word doc :

Code:
Set msword = CreateObject("Word.Application")
Set docs = msword.Documents
msword.Visible = IsVisible
Call docs.Add
Set worddoc = docs(1)
worddoc.Activate

Then, try setting the justification :

Code:
worddoc.activewindow.selection.paragraphformat.alignment = 1

After that, I write into the document without any problem.
 
It's working now.

Must have had some sort of cache problem. I decided to go off and write the rest of the code, which forced to to recompile.
After that, when I tested again, the correct syntax functioned perfectly.
Therefor, it is indeed the line

Code:
worddoc.activewindow.selection.paragraphformat.alignment = 1

that does the trick.

Thanks for your help ! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top