|
求组各位大神。
我有一个outlook的邮件模板,里面有很多数据需要自动更新,代码如下。不知为何不能使用Replace方法,.HTMLBody = Replace(weeklyMSG.HTMLBody, "Index1", "Data1")这一句总是报错。甚至将正文赋值到变量的这两句也会报错 'Dim xbody As String
'xbody = weeklyMSG.HTMLBody。真的不知问题出在哪里。
Sub MailTemplate()
Set FileDialogObject = Application.FileDialog(msoFileDialogFilePicker)
With FileDialogObject
.Title = "Please select the template "
.InitialFileName = ThisWorkbook.Path & "\"
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "Outlooktemplate Files", "*.oft"
If .Show Then
Dim weeklyMSGName As String
weeklyMSGName = .SelectedItems.Item(1)
End If
End With
'Update the tempalte email
Dim OLKapp As Object
Set OLKapp = CreateObject("Outlook.Application")
Dim weeklyMSG As Outlook.MailItem
Set weeklyMSG = OLKapp.CreateItemFromTemplate(weeklyMSGName)
weeklyMSG.Display
'Dim xbody As String
'xbody = weeklyMSG.HTMLBody
With weeklyMSG
.HTMLBody = Replace(weeklyMSG.HTMLBody, "Index1", "Data1")
End With
Set weeklyMSG = Nothing
Set OLKapp = Nothing
End Sub
|
|