我创建了一个Word模板,我需要执行以下操作:
注意:基本模板将根据其数据用于多个收件人。基本上,它与Word对应选项卡所执行的功能几乎相同,只是自定义的。另外,由于有收件人,因此VBA代码位于excel工作表中。
这是我所拥有的代码,一切正常,直到您到达应将内容粘贴到Outlook邮件正文中的行,因为这不会粘贴内容,因此粘贴实际上不起作用。
Sub EnviarRespuestas()
Dim editor, OutApp, Correo As Object
Dim i, j, celda As Integer
Dim pag1 As Worksheet
Set pag1 = ActiveWorkbook.Worksheets("send messages")
wArch = "path of the template"
celda = 11
'create Document of template
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
objWord.documents.Add Template:=wArch, NewTemplate:=False, DocumentType:=0
'Modify document with data of Excel
For k = 6 To 8
With objWord.Selection.Find
.Text = Sheet1.Range("A" & k).Text
.Replacement.Text = Sheet1.Range("C" & k).Text
.Execute Replace:=2
End With
Next k
objWord.Activate
'Copy content of the template modify
objWord.Selection.WholeStory
objWord.Selection.End = objWord.Selection.End - 1
objWord.Selection.Copy
'validate if exists recipients in sheets of excel
Do While Not pag1.Range("J" & celda).Value = ""
Set Correo = OutApp.CreateItem(0)
With Correo
.To = pag1.Range("J" & celda).Value
.Subject = "CURSO: " & pag1.Range("C6").Text
'try of paste content in body
.BodyFormat = olFormatRichText
Set editor = .GetInspector.WordEditor
editor.Content.Paste
.Display
celda = celda + 1
End With
Loop
End Sub
如果有人可以帮助我,我将非常感激。
答案 0 :(得分:2)
几乎可以理解,请在粘贴之前尝试显示。另请参阅我所做的小改动
下面的示例我使用std::vector::assign
docs at cppreference来保持单词doc和签名的格式
Dim Correo As Object
Set Correo = OutApp.CreateItem(0)
Set objWord = Correo.GetInspector.WordEditor
With Correo
.To = pag1.Range("J" & celda).Value
.Subject = "CURSO: " & pag1.Range("C6").Text
.Display 'here
objWord.Paragraphs(1).Range. _
PasteAndFormat Type:=wdFormatOriginalFormatting
End With