Changing paragraph alignment of word document through VBA

左心房为你撑大大i 提交于 2019-12-24 06:49:16

问题


I Have excel workbook which maintains data of my customers Like address & Due amount. I am writing a VBA code in excel which will generate letter to each of the customer for the due amounts. I cannot use mailmerge because of the complexity of the letter. I am using following codes to add paragraphs

Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Add
wrdDoc.content.InsertAfter "----------"
wrdDoc.content.InsertParagraphAfter

Now I need to change alignment of paragraphs. The paragraphs in body of letter are to be justified while some paragraphs like subject line are to be center aligned. I tried this code but its not working

1.

wrdDoc.Paragraphs(8).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter

also

2.

wrdDoc.Paragraphs(8).Alignment = wdAlignParagraphCenter

What is the correct way doing this?

Regards Shekhar


回答1:


http://www.vbaexpress.com/forum/showthread.php?t=29989




回答2:


This worked for me:

objselection.Paragraphs.Alignment = 3

Numbers:

3 Justify 2 Center 1 Right Justify



来源:https://stackoverflow.com/questions/8729424/changing-paragraph-alignment-of-word-document-through-vba

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!