我有一个Outlook的宏,它部分地编辑了电子邮件或日历项的内容,这需要添加“Microsoft Word 14.0对象库”参考。我知道如何在Excel ActiveWorkbook.VBProject.References.AddFromGuid()
中执行此操作,但我找不到有关在Outlook中执行此操作的任何信息。
有可能吗?
每个Remou的示例代码:
Sub CreateNotesEmailFromAppointment()
Dim oMeeting As AppointmentItem
Dim oEmailTemplate As Outlook.MailItem
Dim oEmailWordDoc As Word.Document
If Application.ActiveInspector.CurrentItem.Class = olAppointment Then
Set oMeeting = Application.ActiveInspector.CurrentItem
Set oEmailTemplate = Application.CreateItemFromTemplate(PathToTemplateFile)
oEmailTemplate.Display
Set oEmailWordDoc = Application.ActiveInspector.WordEditor
With oEmailWordDoc.Content.Find
.Text = "<Date>"
.Replacement.Text = Month(oMeeting.Start) & "/" & Day(oMeeting.Start)
.Execute Replace:=wdReplaceAll
End With
'More editing and formatting of oEmailWordDoc follows'
End If
End Sub
答案 0 :(得分:2)
考虑后期绑定:
Dim wd As Object
Set wd = CreateObject("Word.Application")
wd.Visible = True
wd.Documents.Open "C:\Docs\Temp.doc"
如果Word的实例可能正在运行:
On Error Resume Next
Set wd = GetObject(,"Word.Application")
If Err.Number <> 0 Then
Set wd = CreateObject("Word.Application")
End If
wd.Visible = True
这是针对2002年的,但是更新的参考资料是http://support.microsoft.com/kb/307216
如何使用不使用单词的不同方法,而是使用模板的HTMLBody:
Dim oMeeting As AppointmentItem
Dim oEmailTemplate As Outlook.MailItem
If Application.ActiveInspector.CurrentItem.Class = olAppointment Then
Set oMeeting = Application.ActiveInspector.CurrentItem
Set oEmailTemplate = Application.CreateItemFromTemplate(PathToTemplateFile)
oEmailTemplate.Display
oEmailTemplate.HTMLBody = _
Replace(oEmailTemplate.HTMLBody, "<date>", Month(oMeeting.Start) _
& "/" & Day(oMeeting.Start))
End If
答案 1 :(得分:0)
从我可以找到的Outlook VBA出于安全原因不允许这样做。也许创建一个加载项可能是一个解决方案。