我在 Excel VBA 中创建了一个程序,用于将 Word 文档内容复制到邮件正文。
我想改变一篇文字的方向。
我尝试过
.ParagraphFormat.Alignment
。
Sub sendMail()
Dim ol As Outlook.Application
Dim olm As Outlook.MailItem
Dim wd As Word.Application
Dim doc As Word.Document
Dim Cell As Range
For r = 23 To Sheet1.Cells(Rows.Count, 21).End(xlUp).Row
With wd.Selection.Find
.Text = "<<Duration>>"
.Replacement.Text = Sheet1.Cells(r, 32).Value
.Execute Replace:=wdReplaceAll
End With
With wd.Selection.Find
.Text = "<<objectivs>>"
.ParagraphFormat.Alignment = wdAlignParagraphLeft 'this code suppose to change the direction but it didn't work
.Replacement.Text = Sheet1.Cells(r, 33).Value
.Execute Replace:=wdReplaceAll
End With
Next
End Sub
尝试
.Replacement.ParagraphFormat.Alignment = wdAlignParagraphLeft
您的代码正在寻找具有所需对齐方式的段落,而不是设置它。 Selection的使用效率也很低。尝试:
For r = 23 To Sheet1.Cells(Rows.Count, 21).End(xlUp).Row
With wd.ActiveDocument.Range.Find
.Text = "<<Duration>>"
.Replacement.ClearFormatting
.Replacement.Text = Sheet1.Cells(r, 32).Value
.Execute Replace:=wdReplaceAll
.Text = "<<objectivs>>"
.Replacement.ParagraphFormat.Alignment = wdAlignParagraphLeft
.Replacement.Text = Sheet1.Cells(r, 33).Value
.Execute Replace:=wdReplaceAll
End With
Next
请注意,除非您希望更改除第一个 <
我找到了,应该是这样的:
.Replacement.ParagraphFormat.ReadingOrder = wdReadingOrderLtr