通过 VBA 更改 Word 文档的段落对齐方式 [英] Changing paragraph alignment of word document through VBA
问题描述
我有 excel 工作簿,可以维护我的客户数据,例如地址和到期金额.我正在用 excel 编写 VBA 代码,它将为每个客户生成到期金额的信件.由于信件的复杂性,我无法使用 mailmerge.我正在使用以下代码添加段落
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
还有
2.
wrdDoc.Paragraphs(8).Alignment = wdAlignParagraphCenter
这样做的正确方法是什么?
What is the correct way doing this?
问候谢卡尔
推荐答案
这对我有用:
objselection.Paragraphs.Alignment = 3
objselection.Paragraphs.Alignment = 3
数字:
3 证明2中心1 右对齐
3 Justify 2 Center 1 Right Justify
这篇关于通过 VBA 更改 Word 文档的段落对齐方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!