以编程方式在VBA中添加对Outlook 2010的引用

我有一个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

考虑后期绑定:

Dim wd As Object

Set wd = CreateObject("Word.Application")
wd.Visible = True
wd.Documents.Open "C:DocsTemp.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, "&lt;date&gt;", Month(oMeeting.Start) _
          & "/" & Day(oMeeting.Start))
  End If

从我所能找到的Outlook VBA不允许出于安全原因。 也许创建一个加载项将是一个解决方案。

链接地址: http://www.djcxy.com/p/63759.html

上一篇: Programmatically adding References to Outlook 2010 in VBA

下一篇: Working with all outlook versions with Microsoft Outlook 14.0 Object Library