如何使用excel vba更改word文档中的文本

问题描述 投票:0回答:1

我在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
excel vba ms-word text-alignment direction
1个回答
0
投票

尝试

.Replacement.ParagraphFormat.Alignment = wdAlignParagraphLeft
© www.soinside.com 2019 - 2024. All rights reserved.